-1

Using gnome_terminal in my code runs the command I need, however it remains open even after the command has run and profile settings have been set to close after command.

while [ 1 ] 
do
gnome-terminal -x bash -c "sleep 5; pkill omxplayer; pkill gnome_terminal;   echo "done"; bash"
sh issfull.sh
gnome-terminal -x bash -c "sleep 2780.4; pkill omxplayer; bash"
sh nasatv.sh
done
***normal sleep time is 2780.4 which is half of the iss orbital period, but it is shortened to 5
***for testing purposes

I am aware that pkill gnome_terminal doesn't work. It was just the last idea I had to actually get this to work. My gnome_terminal profile settings are set to "When command exits: Exit the terminal" (screenshot)

and here's what happens after the command executes:

image2

Not sure what to do from here, as you can see I've tried using bash to close it and editing the profile settings. I'm afraid to use & in order to run the process in the background because this code is made to run forever and this would likely clog up the raspberry's cpu.

Any help would be much appreciated. Apologies if this doesn't fit site guidelines or is just formatted poorly.

Socowi
  • 25,550
  • 3
  • 32
  • 54
  • `while [ 1 ]` happens to work here but not for the reasons you imagine. It checks whether `1` is not an empty string, which of course it isn't. The usual, idiomatic way to produce an endless loop is `while true` or equivalently (but somewhat obscurely) `while :` – tripleee Mar 03 '19 at 16:33
  • It is extremely unclear why you run these commands in `gnome-terminal` in the first place. The usual way to run a command with a timeout is to run it in the background, then `kill` its PID after a while; look also into the `timeout` command which is installed as standard on some Linux distros. – tripleee Mar 03 '19 at 16:35

1 Answers1

0

The commands you pass to gnome-terminal end with bash. Executing just bash starts an interactive shell that will run until exited manually. The warning "still a process running" refers to that bash command.

Instead of

gnome-terminal -x bash -c "sleep 5; pkill omxplayer; echo "done"; bash"

you should use just

gnome-terminal -- bash -c "sleep 5; pkill omxplayer; echo done"

Also note that you cannot nest quotes (as the syntax highlighting here already suggests). Either write "... echo \"done\"" or just "... echo done" as quotes are not necessary for that specific echo command. Anyways, that echo is not useful as the terminal will close directly after done is printed - the user won't have a change to see the message.

By the way pkill gnome_terminal would have worked with the correct name: pkill gnome-terminal (- not _).

However I wondered why you use gnome-terminal at all. The following script should work as well. If you want to display a message in a dialog to the user, you can use zenity:

while true; do
    sleep 5
    pkill omxplayer
    zenity --info --text done # will wait until user closes information dialog
    sh issfull.sh
    sleep 2780.4
    pkill omxplayer
    sh nasatv.sh
done
Socowi
  • 25,550
  • 3
  • 32
  • 54