腳本自動添加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