Hi Everyone,
I got a problem when I try to pass the return value of a command to a varible, and I've never got the correct value. Please help me out. The ksh shell script looks as:
# check if the application ($1 + $2) is running?
NUMRUN=$(ps -ef | grep $1 | grep $2 | grep -v grep | wc -l)
### $NUMRUN is always 0 no mater how many copies of app are running???
echo $NUMRUN
if [ $NUMRUN -ge 2 ]; then
# running
echo "App has already run\n"
exit 1
else
# not running
exit 0
fi
The sample result of the above script:
8294:/usr/local/p2000/bin> ps -ef |grep PSPG_CipStats |grep -v grep |wc -l
2
8294:/usr/local/p2000/bin>
I guess that the white spaces before '2' may
cause the problem, how can I get rid of them?
Thanks.
Michael
I got a problem when I try to pass the return value of a command to a varible, and I've never got the correct value. Please help me out. The ksh shell script looks as:
# check if the application ($1 + $2) is running?
NUMRUN=$(ps -ef | grep $1 | grep $2 | grep -v grep | wc -l)
### $NUMRUN is always 0 no mater how many copies of app are running???
echo $NUMRUN
if [ $NUMRUN -ge 2 ]; then
# running
echo "App has already run\n"
exit 1
else
# not running
exit 0
fi
The sample result of the above script:
8294:/usr/local/p2000/bin> ps -ef |grep PSPG_CipStats |grep -v grep |wc -l
2
8294:/usr/local/p2000/bin>
I guess that the white spaces before '2' may
cause the problem, how can I get rid of them?
Thanks.
Michael