You are not logged in.
Hello ToZ,
i use Arch Linux with XFCE4 and i want to keep my "/home/USER/.bash_history" file short (with a preselected amount of entries).
So i wrote a simple script, which:
1. kills the running instances of xfce4-terminal
2. copies the content of a textfile to "/home/USER/.bash_history"
3. restarts xfce4-terminal
#!/bin/sh
killall xfce4-terminal
cat /home/USER/infos/system-save/bash_history_orig > /home/USER/.bash_history
/usr/bin/xfce4-terminal
Unfortunately, point 3 does not work, xfce4-terminal does not restart.
I have tried to restart with "xfce4-terminal" and "/usr/bin/xfce4-terminal".
When i use "xfce4-terminal &" for point 3, it starts another instance of the terminal.
What am i doing wrong?
Last edited by h.wurst (2024-10-20 08:33:21)
Offline
How are you running this script? From within xfce4-terminal? Because that will kill the terminal and any child processes.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
How are you running this script? From within xfce4-terminal? Because that will kill the terminal and any child processes.
Yes, i run it from the terminal. Do you have an idea how to achieve the rewriting of the "bash_history" file and continue using the terminal?
Offline
Do you have an idea how to achieve the rewriting of the "bash_history" file and continue using the terminal?
To clear the current history:
history -c
To import a history file:
history -r HISTORYFILE
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Thank you, these work in the terminal, but not as a script.
#!/bin/sh
history -c && history -r /home/USER/infos/system-save/bash_history_orig
Does not work.
Last edited by h.wurst (2024-10-17 03:16:22)
Offline
Try this.
First make sure your bash_history_orig file is not writeable so bash doesn't add to it:
chmod a-w /home/USER/infos/system-save/bash_history_orig
Then the script:
#!/bin/sh
pkill xfce4-terminal
HISTFILE=/home/USER/infos/system-save/bash_history_orig xfce4-terminal -e bash
And finally, run the script with "nohup":
nohup MYSCRIPT.sh
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Try this.
First make sure your bash_history_orig file is not writeable so bash doesn't add to it:
chmod a-w /home/USER/infos/system-save/bash_history_orig
Then the script:
#!/bin/sh pkill xfce4-terminal HISTFILE=/home/USER/infos/system-save/bash_history_orig xfce4-terminal -e bash
And finally, run the script with "nohup":
nohup MYSCRIPT.sh
This script does not empty/shorten the file "/home/USER/.bash_history" the unwanted entries remain in the file.
This script produces for each instance a file named "/home/USER/nohup.out" which contains some error messages.
Offline
This script does not empty/shorten the file "/home/USER/.bash_history" the unwanted entries remain in the file.
It won't - it is redirecting that bash session to use another history file - the back up one. If you want /home/USER/.bash_history to also be cleared, add a:
> /home/USER/.bash_history
...after the pkill command.
This script produces for each instance a file named "/home/USER/nohup.out" which contains some error messages.
What are the error messages? You can redirect the nohup.out file to /dev/null if you don't want it to be created:
nohup MYSCRIPT.sh > /dev/null
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
i think i will have to read a little bit more on the bash history and do some experiments.
THANK YOU for running this support forum
Are you really doing all this alone or is ToZ a group of people?
Last edited by h.wurst (2024-10-20 08:23:48)
Offline
Are you really doing all this alone or is ToZ are group of people?
There are others who contribute regularly as well. Everyone's contributions are appreciated.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
To clear the current history:
history -c
To import a history file:
history -r HISTORYFILE
Thank you for this hint, it is a much better solution (than my idea was) for this problem.
Last edited by h.wurst (2024-10-20 08:44:31)
Offline
[ Generated in 0.011 seconds, 7 queries executed - Memory usage: 572.03 KiB (Peak: 588.88 KiB) ]