Reputation: 2915
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 directly without creating the file. Any suggestions?
Upvotes: 2
Views: 8104
Reputation: 6387
( crontab -l 2>/dev/null | grep -Fv ntpdate ; printf -- "*/3 * * * * /usr/sbin/ntpdate 192.168.2.3" ) | crontab
Upvotes: 9
Reputation: 276
Use >> "append" instead of > "output"
#!/bin/bash
Task="'*/3 * * * * /usr/sbin/ntpdate 192.168.2.3'";
$Task >> date.cron;
Greetings.
Upvotes: 1