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.
精彩评论