Reputation: 13
So i am writing a script to call a process 365 times and they should run in 10 batches, so this is something i wrote but there are multiple issues - 1. the log message is not getting written to the log file, i see the error message in err file 2. there is this "Command not found" error I keep getting from the script for the line process. 3. even if the command doesnt succeed, still it doesn't print FAIL but prints success
#!/bin/bash
set -m
FAIL=0
for i in {1..10}
do
waitPIDS=()
j=$i
while [ $j -lt 366 ]; do
exec 1>logfile
exec 2>errorfile
`process $j &`
waitPIDS[${#waitPIDS[@]}]=$!
j=$[$j+1]
done
for jpid in "${waitPIDS[@]}"
do
echo $jpid
wait $jpid
if [[ $? != 0 ]] ; then
echo "fail"
else
echo "success"
fi
done
done
What is wrong with it ?
thanks!
Upvotes: 1
Views: 816
Reputation: 224844
At the very least, this line:
`process $j &`
Shouldn't have any backticks in it. You probably just want:
process $j &
Besides that, you're overwriting your log files instead of appending to them; is that intended?
Upvotes: 1