I created a shell script which I am running using nohup. This script runs various sql script in sequence but few in parallel also. I have the following statements in my script-
echo exit | sqlplus -s ${username}/${pwd}@${DB} @close1.sql
echo exit | sqlplus -s ${username}/${pwd}@${DB} @close2.sql
echo exit | sqlplus -s ${username}/${pwd}@${DB} @insertPricing1.sql &
pid1=$!
echo exit | sqlplus -s ${username}/${pwd}@${DB} @insertPricing2.sql &
pid2=$!
echo "Pricing Insert PIDs => ${pid1}, ${pid2}"
while [ `ps -p ${pid1},${pid2} | wc -l` > 1 ]
do
sleep 5
done
echo exit | sqlplus -s ${username}/${pwd}@${DB} @insertPricing3.sql
The intention is to run close1 -> close2 -> insertPricing1 & insertingPricing2 in parallel -> insertPricing3. where -> means in sequence.
When I checked the result the next day (after sufficient time it should have been completed), I saw that the shell script was still running. Pricing1 and Pricing2 were done but Pricing3 didn't start. The processes for 1 and 2 had finished.
ps -p 19105,19107
PID TTY TIME CMD
There is some problem in the while loop as when I run this in
# ps -p 19105,19107 | wc -l
1
but this-
# while [ `ps -p 19105,19107 | wc -l` > 1 ]
> do
> echo "hello"
> done
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
........ ctrl+C
so why this loop works when 1 is not greater than 1? What should be the solution?