开发者

write a shell script to add job to cron

I write a shell script below to add a job to cron.

#!/bin/sh
touch date.cron
echo '*/3 * * * * /usr/sbin/ntpdate 192.168.2.3' >date.cron
crontab date.cron
rm date.cron

But I don't want to create the file date.cron. How can I add the job开发者_Go百科 directly without creating the file. Any suggestions?


( crontab -l 2>/dev/null | grep -Fv ntpdate ; printf -- "*/3 * * * * /usr/sbin/ntpdate 192.168.2.3" ) | crontab


Use >> "append" instead of > "output"

#!/bin/bash
Task="'*/3 * * * * /usr/sbin/ntpdate 192.168.2.3'";
$Task >> date.cron;

Greetings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜