2014-03-05 43 views
0

在Mac(Mavericks)上工作,并在9到5pm之间每5分钟运行一个shell脚本。在这些时间之外,我不希望它运行。使用launchd或Lingon在特定时间段内安排命令

运行从终端的剧本,我发出以下命令:

./script.sh < list.txt 

因为我要过,我一直试图让launchd的时候一直有问题LIST.TXT文件脚本运行脚本(完全没有我想要的时间表)。我一直在使用Lingon3来创建plist(对于其他命令,在我没有将脚本文件传递给脚本的情况下正常工作,因为我处于这种情况)。我也试过把完整路径(

/full/path/to/script.sh < /full/path/to/list.txt

而且这也不行。

请帮助a)启动以执行上面的命令,并b)创建一个plist,在一天中的特定时段之间定期运行命令。

感谢您的帮助

回答

0

你可以只列出小时和分钟的每个组合:

for h in {9..17};do for m in $(seq 0 5 55);do echo "<dict><key>Hour</key><integer>$h</integer><key>Minute</key><integer>$m</integer></dict>";done;done

您也可以运行该脚本每隔一小时,但根据日期退出它:

hour=$(date +%H);[[ $hour -ge 9 && $hour -le 17 ]]||exit 

或者使用cron代替。运行crontab -e(或EDITOR=nano crontab -e),并添加这样一行:

*/5 9-17 0 0 0 /full/path/to/script.sh < /full/path/to/list.txt 

您可以使用StandardInPath从文件标准输入得到:

<key>Program</key> 
<string>/full/path/to/script.sh</string> 
<key>StandardInPath</key> 
<string>/full/path/to/list.txt</string> 

或者使用bash -c

<key>ProgramArguments</key> 
<array> 
    <string>bash</string> 
    <string>-c</string> 
    <string>/full/path/to/script.sh &lt; /full/path/to/list.txt</string> 
</array> 
+0

我是新来的launchd,没能得到它的工作,所以想你的cron的例子 - 在做的时候它,我收到了一个错误:使用你的例子“糟糕的日子” – gcubed

0

的launchd不支持cron风格的时间规格。您必须手动指定每隔5分钟在9AM和5PM之间的时间戳。 LaunchControl允许您指定的时间间隔的cron风格,并生成相应的键为您提供:

Config section in LaunchControl

相关问题