Xfce Forum

Sub domains
 

You are not logged in.

#1 2024-10-16 05:45:27

h.wurst
Member
Registered: 2020-11-20
Posts: 24
LinuxFirefox 131.0

[solved] how to restart xfce4-terminal from a script?

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

#2 2024-10-16 13:09:00

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,482
Windows 10Microsoft Edge 129.0

Re: [solved] how to restart xfce4-terminal from a script?

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

#3 2024-10-16 15:31:52

h.wurst
Member
Registered: 2020-11-20
Posts: 24
LinuxFirefox 131.0

Re: [solved] how to restart xfce4-terminal from a script?

ToZ wrote:

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

#4 2024-10-17 01:29:39

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,482
LinuxFirefox 131.0

Re: [solved] how to restart xfce4-terminal from a script?

h.wurst wrote:

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

#5 2024-10-17 03:07:14

h.wurst
Member
Registered: 2020-11-20
Posts: 24
LinuxFirefox 131.0

Re: [solved] how to restart xfce4-terminal from a script?

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

#6 2024-10-17 13:45:28

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,482
LinuxFirefox 131.0

Re: [solved] how to restart xfce4-terminal from a script?

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

#7 2024-10-18 05:19:08

h.wurst
Member
Registered: 2020-11-20
Posts: 24
LinuxFirefox 131.0

Re: [solved] how to restart xfce4-terminal from a script?

ToZ wrote:

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

#8 2024-10-18 10:34:11

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,482
LinuxFirefox 131.0

Re: [solved] how to restart xfce4-terminal from a script?

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

#9 2024-10-19 06:14:08

h.wurst
Member
Registered: 2020-11-20
Posts: 24
LinuxFirefox 131.0

Re: [solved] how to restart xfce4-terminal from a script?

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  smile

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

#10 2024-10-19 10:37:44

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,482
LinuxFirefox 131.0

Re: [solved] how to restart xfce4-terminal from a script?

h.wurst wrote:

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

#11 2024-10-20 08:32:49

h.wurst
Member
Registered: 2020-11-20
Posts: 24
LinuxFirefox 131.0

Re: [solved] how to restart xfce4-terminal from a script?

ToZ wrote:

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

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.011 seconds, 7 queries executed - Memory usage: 572.03 KiB (Peak: 588.88 KiB) ]