Reputation: 1067
I'm trying to create a very simple bash script where I need to list,insert and remove my cronjobs. I'm doing the listing using crontab -l and I remove the all using crontab -r. But when i wanna insert one, my code does not work (it does not actually add the cronjob to /etc/crontab),even it does not throw any error. My code is the following:
echo "Time to be Executed"
echo -m "Enter minute:"
read m
echo -h "Enter hour:"
read h
echo -dom "Enter day of month:"
read dom
echo -mon "Enter month:"
read mon
echo -dow "Enter day of week (number or first three characters ex 1 or Mon):"
read dow
echo -j "Enter job to be executed:"
read j
echo "$m $h $dom $mon $dow root $j" >> /etc/crontab;
Do you see anything that i've done wrong here? Any help would be highly appreciated,thanks!!
Upvotes: 0
Views: 287
Reputation: 31349
I've tested your script and it works. Make sure you have the right permissions (sudo ./myscript.sh
).
Perhaps replace the last line with:
echo "$m $h $dom $mon $dow root $j" | sudo tee -a /etc/crontab
Upvotes: 1