(编辑:jimmy 日期: 2024/12/26 浏览:2)
脚本自动添加crontab
复制代码 代码如下:
#!/bin/sh
BASEDIR=`dirname $0`/..
BASEDIR=`(cd "$BASEDIR"; pwd)`
PROGRAM=$BASEDIR/bin/daemon.sh
CRONTAB_CMD="*/1 * * * * sh $PROGRAM once > /dev/null 2>&1 &"
(crontab -l 2>/dev/null | grep -Fv $PROGRAM; echo "$CRONTAB_CMD") | crontab -
COUNT=`crontab -l | grep $PROGRAM | grep -v "grep"|wc -l `
if [ $COUNT -lt 1 ]; then
echo "fail to add crontab $PROGRAM"
exit 1
fi