Home > Net >  Add new command to a specific line in crontab
Add new command to a specific line in crontab

Time:09-26

I want to add this command to line 26 in crontab.

00 09 * * * sudo /usr/sbin/shutdown -h now

How do I add this command specifically to line 26 in crontab? Also, how do I make it so if there's existing text in line 26, this new line of text will replace the previous text in line 26?

Thank you.

EDIT: I tried crontab -l | sed -i '26/00 09 * * * sudo /usr/sbin/shutdown -h now' | crontab - but it said "no input files"

CodePudding user response:

Using sed

sed -i.bak '26s~.*~00 09 * * * sudo /usr/sbin/shutdown -h now~' /var/spool/cron/root
  • Related