Example forever loop and if status is 0, then break the loop. Case is nice command to use string comparing.
#!/bin/bash
# or ksh
while true
do
# your db code here
# after that:
case "$STATUS" in
0) break ;; # break loop
4) echo "status 4" ;;
NOT*YET*RUN) echo "status not yet" ;;
#....
*) echo "other status $STATUS" ;;
esac
sleep 10 # sleep 10 sec and poll again
done
echo "Done"
Thanks hergp. I tried this code but facing some issue.
if i hard code like status=0 or with some other values (4,Not Yet Run) the script is working fine .But if i am pulling the status value from db, every time it is moving in to other status for all the values 0,4, and Not yet run.
If I use Status=0 in the script no issue. It is immediately coming out of the loop because of break condition in the case statement
But if I fetch Status value from DB like below.
Status= db2 " Select Status from X table" then it is returning "Other Status 0" from the case statement which is wrong. It has to immediately come out of the loop. But its not happening
---------- Post updated at 06:47 AM ---------- Previous update was at 06:34 AM ----------
Currently the status value is '0' . But if I ran the below script it is returning "Other Status 0"
while true
do
db2 connect
STATUS=$(db2 -x "SELECT JOB_STATUS FROM X WHERE NAME='Test1'")
# after that:
case "$STATUS" in
'0') break ;; # break loop
'4') echo "status 4" ;;
'NOT*YET*RUN') echo "Job Running" ;;
#....
*) echo "other status $STATUS" ;;
esac
sleep 10 # sleep 10 sec and poll again
done
echo "Done"