Operating System - HP-UX
1837897 Members
3250 Online
110123 Solutions
New Discussion

Re: script that waits for another one to finish...

 
SOLVED
Go to solution
Ratzie
Super Advisor

script that waits for another one to finish...

I need to put together a script, that shuts down the sysedge (under root) at a certain time, I can handle this no prob via roots crontab, but I also want to start the sysedge up after another script runs.
What I am thinking is in a script...

/sbin/init.d/sysedge stop

Here is where I write a command to wait for the next script to finish, under another user,
then...
(how do I do this)

/sbin/init.d/sysedge start

Yes, I tried writing it all in one script, but the middle script needs to run as another user, and when I try to stop the sysedge with that user, but set the sysedge script to chmod u+s, (sticky bit), it looks like it stops it, but it does not.
6 REPLIES 6
Nicolas Dumeige
Esteemed Contributor

Re: script that waits for another one to finish...

The classic synchronisation mecanism :
- flag file (with a timestamp)
- pipe
or ugly one, "ps" look up, status evaluatio, i.e. what is supposed to modify the first script, if it's done, the script has completed.

As for the change of user, if you have superuser provilige, use su :
su - anotherusether -c "command"

good luck
All different, all Unix
Ratzie
Super Advisor

Re: script that waits for another one to finish...

yes, I run the su in the crontab for another user

00 01 * * 1 su admin -c /home/admin/scripts/backup/backup.sh >/dev/null

What I did try was...
00 01 * * 1 /home/scripts/stopsysedge ; su admin -c /home/admin/scripts/backup/backup.sh >/dev/null; /home/scripts/startsysege

The stop sysedge works fine but nothing else.
Chris Vail
Honored Contributor
Solution

Re: script that waits for another one to finish...

I usually do this with a lock file. The lock file is created when the first script runs, the second waits for the lock to be removed.

In the first script, near the top:

touch $DIR/LOCKFILE
(the rest of your script here)
rm $DIR/LOCKFILE

In the second script, near the top:

while true
do
if test -f $DIR/$LOCKFILE
then
sleep 60
else
break
fi
done
(the rest of your script here)



Chris
A. Clay Stephenson
Acclaimed Contributor

Re: script that waits for another one to finish...

Scripts under /sbin/init.d can be tricky because they often fork() and exec() so that using a wait command may not behave as expected.

The standard method is:
mycmd.sh &
CHILD_PID=${!}
wait ${CHILD_PID} # parent will wait until child finishes

Again, depending upon whether of not this child fork()'s and exec()'s, wait may not do what you want.

Probably the best technique is to have the "stop" process create a file when it is finished and then have the "start" process loop with a sleep until the file appears.

This is a pretty standard technique for synchronizing groups of unrelated processes.
If it ain't broke, I can fix that.
Nicolas Dumeige
Esteemed Contributor

Re: script that waits for another one to finish...

Why don't use su to make the uniq script you want to do in the first place ?
All different, all Unix
Ratzie
Super Advisor

Re: script that waits for another one to finish...

Thanks