I wanted to run a command on our linux after its done rebooting, I saw that it can be done using crontab. I wanted to run this command
sudo ifdown eth0 && sudo ifup -v eth0
on the crontab can i just do:
@reboot sudo ifdown eth0 && sudo ifup -v eth0
or do i need to store that in a script?
thank you
Best Answer
A few notes here before this would work:
sudo
in a cron job. Instead editroot
's crontab instead of your own, e.g.sudo crontab -e
and then enter commands withoutsudo
.cron
, and would likely be better placed in/etc/rc.local
before theexit 0
line.@reboot
should also run after a hard shutdown or crash, but there are different cron implementations so YMMV. I've seen comments in different places asserting both.EDIT (2016/02/17): Removed incorrect blurb on absolute paths; kudos @muru
EDIT (2016/10/17): Added shutdown note
EDIT (2017/09/11): Revised shutdown note. Not really sure on that one.