start.sh
PID=`ps -ef | grep 'anticheat' | grep -v 'grep' | awk '{print $2;}'`
if [ ! -z "$PID" ]; then
echo "PID FOUNDED :" $PID
echo "IF YOU WANNA TO RESTART, PLEASE USE THE RESTART SCRIPT"
exit
else
# start service
if [ -z "$PID" ]; then
echo "START SERVER ERROR"
exit
else
echo "START SERVER SUCCESSFULLY"
fi
fi
output for commend line
++ pwd
+ cur_dir=/search/odin/online/anticheat
+ anticheat_bin=anticheat
++ ps -ef
++ grep anticheat
++ grep -v grep
++ awk '{print $2;}'
+ PID=17821
+ '[' '!' -z 17821 ']'
+ echo 'PID FOUNDED :' 17821
PID FOUNDED : 17821
+ echo 'IF YOU WANNA TO RESTART, PLEASE USE THE RESTART SCRIPT'
IF YOU WANNA TO RESTART, PLEASE USE THE RESTART SCRIPT
+ exit
it can work rightly when I run a bash shell in commend line, however it doesn't work as expected in crontab.
++ grep anticheat
++ grep -v grep
++ ps -ef
++ awk -F ' ' '{print $2}'
+ PID='17821
23184'
how can I fix it?