LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 09-02-2006, 06:42 AM   #1
linuxhippy
Senior Member
 
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Xubuntu, Mythbuntu, Lubuntu, Picuntu
Posts: 1,185

Rep: Reputation: 47
add to a running script


I'm running a bunch of scripts that start realplayer with vsound and can only start after previous scripts have finished (I think only 1 instance of vsound can operate at time). How can I put script in a "que" so that they start up once the running scripts have stopped?
 
Old 09-02-2006, 09:42 AM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,950
Blog Entries: 5

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
Just create a script that waits kicks off each of the scripts in turn:

Say you have scripts: script1.sh, script2.sh and script3.sh

Just create a new script called masterscript.sh that has:

script1.sh
script2.sh
script3.sh

So long as none of the scripts include a background (e.g. has an & at the end of the line or the utility itself automatically backgrounds) they'll run sequentially.

If something is being backgrounded you'll have to test for it:

script1.sh
while ps -ef |grep <script1.sh>
do sleep 60
done
script2.sh
while ps -ef |grep <script2.sh>
do sleep 60
script3.sh

The above starts script1.sh then checks every minute to see if it is still running. If not it will proceed on to script2.sh. It then checks every minute to see if script2.sh is done and will kick off script3.sh.

Note that you may not want to check for "script#.sh" but rather the command that it contains.

Also the sleep is important to keep the script from chewing up CPU. Without a sleep it would quickly peg your CPU. Even a sleep 1 would be better than no sleep but 60 seconds isn't excessive.
 
Old 09-02-2006, 10:02 AM   #3
linuxhippy
Senior Member
 
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Xubuntu, Mythbuntu, Lubuntu, Picuntu
Posts: 1,185

Original Poster
Rep: Reputation: 47
I am not backgrounding my scripts. I have script1.sh and script2.sh and run them this way:

sh script1.sh
sh script2.sh

These scripts take hours to run, so during that time I make script3.sh and script4.sh. How do I add script3.sh and script4.sh to my masterscript so that script3.sh starts when script2.sh ends? It sounds like I do this instead:

sh masterscript.sh

and then update the script list in masterscript.sh while it is executing-is that right?

Last edited by linuxhippy; 09-02-2006 at 10:06 AM.
 
Old 09-02-2006, 10:26 AM   #4
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,950
Blog Entries: 5

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
If script1.sh and script2.sh are already running (from masterscript.sh) then you can't add to masterscript.sh. You would create a new one (masterscript2.sh) that would test for completion of script1.sh and script2.sh then run script3.sh:

while ps -ef |egrep "script1.sh|script2.sh" |grep -v egrep
do sleep 60
done
script3.sh
while ps -ef |grep script4.sh
do sleep 60
script3.sh

Note I'd left out the grep -v earlier but shouldn't have. You need this so it doesn't find your grep process as the only one running. This is necessary so it doesn't incorrectly show the script running when all it actually found was your grep command.

egrep allows for multiple patterns - the quotes are necessary around the patterns and the pipe sign (|) means "or" for egrep.

You would do the above if it is running script1 or script2 already. I'd suggest you make the masterscript with all 4 scripts in it before the next time you start script1.
 
  


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
add user script satinet Linux - General 2 10-21-2005 02:48 AM
how to add a sh-script to the autostart JohnWayne Linux - General 1 09-18-2004 09:09 AM
Script to add users ssudhi Linux - Newbie 3 05-01-2004 04:33 AM
add user script? ezra143 Linux - Software 2 10-21-2003 11:21 PM
How to add something in init script Ypkis Linux - Newbie 5 10-12-2003 06:35 AM


All times are GMT -5. The time now is 06:15 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration