crontab和screen不能一起用么?
发表于 : 2013-10-25 13:11
我写了一个脚本。想放到cron里面每分钟运行一次。但是发现脚本里面只有screen那行没执行,请各位大侠帮帮忙啊。
monitor.sh
crontab中的写法
monitor.sh
代码: 全选
#!/bin/bash
HLDS_PATH="/usr/local/games/cs"
HLDS_PROGRAM="hlds_run"
MONITOR_FILE="monitor.log"
HLDS_RUN="$HLDS_PATH/$HLDS_PROGRAM -game cstrike -port 27015 +maxplayers 15 +sv_lan 0 -console -pingbooster 2 -noaff -noipx +map de_inferno -heapsize 131072 -zone 4096"
nc -z -w 5 -u 127.0.0.1 27015 > /dev/null 2>&1
if [ $? -ne 0 ]
then
killall hlds_linux > /dev/null 2>&1
killall hlds_run > /dev/null 2>&1
killall screen > /dev/null 2>&1
screen -wipe
/usr/bin/screen -AmdS hlds $HLDS_RUN
sleep 5
HLDS_PID=`ps -A | awk '/hlds_linux/ { print $1 }'`
renice -15 -p $HLDS_PID > /dev/null 2>&1
echo "`date`:重启服务" >> $HLDS_PATH/$MONITOR_FILE
fi
exit 0
crontab中的写法
代码: 全选
* * * * * root /usr/local/games/cs/monitor27015 >> /test.log 2>&1