- 论坛徽章:
- 0
|
Shell脚本如下:
#!/bin/ksh
SCRIPTNAME=`/bin/basename $0`;
SID=$1;
proccnt=`ps -ef |grep $SCRIPTNAME |grep $SID |grep -v grep |wc -l`;
echo "output from: ps -ef |grep $SCRIPTNAME |grep $SID |grep -v grep |wc -l"
ps -ef |grep $SCRIPTNAME |grep $SID |grep -v grep |wc -l
echo "echo proccnt"
echo $proccnt;
if [ $proccnt -gt 1 ]
then
echo "Another $SCRIPTNAME is running. Abort."
proccnt=`ps -ef |grep $SCRIPTNAME |grep $SID`
echo "$proccnt"
exit;
else
echo 'proccnt<=1';
fi
输出如下:
svr:elcaro /tmp/test1.sh eddy
output from: ps -ef |grep test1.sh |grep eddy |grep -v grep |wc -l
1
echo proccnt
2
Another test1.sh is running against the same DB. Abort.
elcaro 22231 18860 3 05:48 pts/0 00:00:00 /bin/ksh /tmp/test1.sh eddy
elcaro 22244 22231 0 05:48 pts/0 00:00:00 /bin/ksh /tmp/test1.sh eddy
svr:elcaro
为何直接ps出来的值是1, 赋给一个变量之后就变成2了呢.
高手赐教.
|
|