Re: bash scripting: eval and waiting for processes in background



I have a directory with some scripts with similar names, that I would like
to run. I would like to run them all from another script, without having
to specify their individual names. Because in the future I may add other
scripts, and then I don't have to change the master script.
I tried this:

SCRIPTS=`ls /root/bin/hotcopy-*.sh`
eval "$SCRIPTS" &
wait
echo "Continue master script."

Works great, except for one little detail.
I added echo lines at the start and end of each script for debugging
purpose. Because the & moves the process to the background, I expected to
see the following output:

Script 1 starting...
Script 2 starting...
Script 3 starting...
Script 4 starting...
Script 1 done.
Script 4 done.
Script 3 done.
Script 2 done.
Continue master script.

The real output is:

Script 1 starting...
Script 1 done.
Script 2 starting...
Script 2 done.
Script 3 starting...
Script 3 done.
Script 4 starting...
Script 4 done.
Continue master script.

So this means that the scripts aren't running simultaneous. It's not a big
issue, but they are all independent. Each script stops a service, runs
some maintenance (seconds to several minutes) and restarts the service, so
I'd like to keep the total service downtime as short as possible.

I suspect that the problem is with the eval command parsing multiple
scripts at once. I tried moving the & inside the quotes, but that doesn't
make a difference.

eval will only background the last script whether you put the & inside
or outside the ".

A loop should do the trick.

I am not sure whether it will run the scripts simultaneously, but you
could also test run-parts rather than use a loop.

--
ubuntu-users mailing list
ubuntu-users@xxxxxxxxxxxxxxxx
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users



Relevant Pages

  • Re: Variables not passed out of WHILE
    ... that values of a string are not passed out of a WHILE ... loop. ... My script will not ECHO the value of $var at the end. ...
    (comp.unix.shell)
  • Re: renaming files via shell script
    ... what I meant by somefile. ... echo "in for loop" ... I get 'in script' but not 'in for loop'. ...
    (comp.os.linux.misc)
  • Re: How to get an interation count from a while loop (bash)
    ... I am trying to count how many times a while loop iterates. ... echo Total Lines Read is $LOOP_COUNT ... The usage for this script is ... The usage for the above script is: ...
    (comp.os.linux.misc)
  • Re: How do I get this out?
    ... There are so many ways to retirve information from a database. ... I use a loop for the most of the time. ... echo $linkage; ... I've edit the script a bit and got rid of some of the complex scripts ...
    (alt.php)
  • Re: tcsh read loop
    ... > echo $line ... > Can this type of loop, that reads a complete line from a file, be done in ... You have to split this script into smaller scripts, and change STDIN. ...
    (comp.unix.shell)