LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-26-2008, 06:46 PM   #1
computer_freak_8
Member
 
Registered: Jul 2008
Location: Iowa
Distribution: Ubuntu and Fedora, mostly
Posts: 103

Rep: Reputation: 15
Question 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.
 
Old 12-26-2008, 08:18 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
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
 
Old 12-26-2008, 08:59 PM   #3
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41
Quote:
Originally Posted by computer_freak_8 View Post
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.
 
Old 12-27-2008, 08:13 AM   #4
computer_freak_8
Member
 
Registered: Jul 2008
Location: Iowa
Distribution: Ubuntu and Fedora, mostly
Posts: 103

Original Poster
Rep: Reputation: 15
Thumbs up 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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
running a shell script which invokes another shell program!!! raghu123 Programming 1 08-04-2008 09:10 AM
running a C program from shell script jkeertir Linux - Newbie 3 05-19-2008 05:05 AM
How to open a program in another shell julian_s Linux - General 1 12-22-2005 03:54 PM
Communication between shell script and program ZooL Programming 6 08-14-2004 05:44 AM
run shell script in c program u4u Linux - General 1 02-14-2004 02:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration