Reputation: 37
It seems the code after if
/fi
is not running. Here is what I have:
I have a script, /my/scripts/dir/directoryPercentFull.sh:
directoryPercentFull="$(df | grep '/aDir/anotherDir' | grep -o '...%' | sed 's/%//g' | sed 's/ //g')"
if [ $directoryPercentFull -gt 90 ]
then
echo $directoryPercentFull
exec /someDir/someOtherDir/test01.sh &
exec /someDir/someOtherOtherDir/test02.sh &
exec /someDir/yetAnotherDir/test03.sh
fi
echo "Processing Done"
The scripts being called are: /someDir/someOtherDir/test01.sh
#!/usr/bin/env bash
echo "inside test01.sh"
sleep 5
echo "leaving test01.sh"
/someDir/someOtherOtherDir/test02.sh
#!/usr/bin/env bash
echo "inside test02.sh"
sleep 5
echo "leaving test02.sh"
/someDir/yetAnotherDir/test03.sh
#!/usr/bin/env bash
echo "inside test03.sh"
sleep 5
echo "leaving test03.sh"
running the script by cd-ing to /my/scripts/dir and then doing ./directoryPercentFull.sh gives: OUTPUT:
93
inside test03.sh
inside test02.sh
inside test01.sh
leaving test03.sh
leaving test01.sh
leaving test02.sh
OUTPUT EXPECTED:
93
inside test01.sh
inside test02.sh
inside test03.sh
leaving test01.sh
leaving test02.sh
leaving test03.sh
Processing Done
The order of the echo commands are not that big of a deal, though if someone knows why they go 3,2,1, then 3,1,2, I wouldn't hate an explanation.
However, I am not getting that final Processing Done
. Anyone have any clue why the final echo
back in /my/scripts/dir/directoryPercentFull.sh
does not occur? I have purposefully not placed an &
after the last exec
statement, as I don't want what what is after the if
/fi
to run until all of it is finished processing.
Upvotes: 1
Views: 1157
Reputation: 361730
/someDir/someOtherDir/test01.sh &
/someDir/someOtherOtherDir/test02.sh &
/someDir/yetAnotherDir/test03.sh
Get rid of all the exec
s. exec
causes the shell process to be replaced by the given command, meaning the shell does not continue executing further commands.
The order of the echo commands are not that big of a deal, though if someone knows why they go 3,2,1, then 3,1,2, I wouldn't hate an explanation.
The printouts could come in any order. The three scripts are run in parallel processes so there's no telling which order they echo
their printouts.
Upvotes: 2