我在最近3个小时内努力让Mac OS X 10.11.5中每小时运行一个脚本。这是我所拥有的,计划每分钟运行一次以进行测试(似乎没有执行):
C02QT2UBFVH6-lm:position_scheduler gsamaras$ cat position.sh
#!/bin/bash
current_hour="`date +%H`";
echo $current_hour;
osascript -e 'display notification "Hour '$current_hour'" with title "Title"'
filename=state.txt
oldState="`cat /Users/gsamaras/Documents/position_scheduler/state.txt`"
newState=$((1-oldState))
if [ -f "$filename" ]
then
echo "$newState" > "$filename"
echo $newState
fi
C02QT2UBFVH6-lm:position_scheduler gsamaras$ cd
C02QT2UBFVH6-lm:~ gsamaras$ crontab * * * * * root /Users/gsamaras/Documents/position_scheduler/position.sh
C02QT2UBFVH6-lm:~ gsamaras$ crontab -l
C02QT2UBFVH6-lm:~ gsamaras$ crontab * * * * * /Users/gsamaras/Documents/position_scheduler/position.sh
C02QT2UBFVH6-lm:~ gsamaras$ crontab -l
C02QT2UBFVH6-lm:~ gsamaras$
我错过了什么?
我也尝试过:
C02QT2UBFVH6-lm:~ gsamaras$ export EDITOR=nano
C02QT2UBFVH6-lm:~ gsamaras$ crontab -e
crontab: installing new crontab
"/tmp/crontab.clUrdAyyv9":0: bad minute
crontab: errors in crontab file, can't install
Do you want to retry the same edit? n
crontab: edits left in /tmp/crontab.clUrdAyyv9
C02QT2UBFVH6-lm:~ gsamaras$ cat /tmp/crontab.clUrdAyyv9
crontab * * * * * /Users/gsamaras/Documents/position_scheduler/position.sh