LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Shell script: Open program when closed? (https://www.linuxquestions.org/questions/programming-9/shell-script-open-program-when-closed-693163/)

computer_freak_8 12-26-2008 06:46 PM

Shell script: Open program when closed?
 
Okay, here's the deal: I'm wanting to write a shell script that will act daemon-ish, and that I can set to run at login on a per-user basis.

The pseudo-code for what I am trying to accomplish would probably be something like:

Code:

(_beginning_)
if {firefox is not running}
then {start firefox}
else {wait until firefox closes}
(goto "beginning")

Does anyone have any ideas on how to do this?


Note: This is for an experimental kiosk-type environment.

ilikejam 12-26-2008 08:18 PM

Hi.

You'd probably be better just using a while loop, e.g.
Code:

#!/bin/bash
while true
do
    firefox
done

With that every time firefox exits, it'll go round the loop and restart it.

Dave

lwasserm 12-26-2008 08:59 PM

Quote:

Originally Posted by computer_freak_8 (Post 3388057)
Okay, here's the deal: I'm wanting to write a shell script that will act daemon-ish, and that I can set to run at login on a per-user basis.

The pseudo-code for what I am trying to accomplish would probably be something like:

Code:

(_beginning_)
if {firefox is not running}
then {start firefox}
else {wait until firefox closes}
(goto "beginning")

Does anyone have any ideas on how to do this?


Note: This is for an experimental kiosk-type environment.

Presumably for kiosk use you will have a user account set up with limited priveledges, restricted shell, etc. You could put something like this in that user's .profile or shell rc file:

while true;
do firefox;
done

The user could of course switch focus to the terminal where the shell is running and Ctrl-C out of the loop. Maybe slightly better would be logging in on a vt and using xinit to run only firefox and nothing else in an X session.

But why reinvent the wheel? There are packages like pessalus (not sure of spelling) that are made for this purpose and have already taken security into consideration.

computer_freak_8 12-27-2008 08:13 AM

Solution found!
 
Thank you both so much.

I discovered that Firefox is set to automatically start when the X server starts. When Firefox is closed, it shuts down the X server.

So, here's what I added to the "~/.profile" file:
Code:

while true
do startx
done

As a test (after a reboot), I switched to the terminal and hit [Ctrl]+[C]. The X server quit and restarted, which in turn reopened Firefox.


Thanks again,
computer_freak_8


All times are GMT -5. The time now is 07:18 AM.