Setting cron to be run as root

In Linux based distros, its very simple to setup cron for repeated tasks by using `crontab -e` for editing the crontab of the current user as you are logged in. You can view the contents of your crontab by `crontab -l`.

But if you need to call something with root privileges, its as simple as `sudo crontab -e`. This adds your changes to root user’s crontab. To view root user’s crontab, you can again do `sudo crontab -l` and you can see the difference.

Bonus tip: The first time you open crontab for editing, it opens it in vim. Those of you who are hardcore guys, know their way around, but they are not reading this anyway. I am not hardcode, I do know basic vim commands, but I like to use nano. If you are on the same boat as me, use this `export EDITOR=nano`. Now go get shit done!


Leave a Reply

Your email address will not be published. Required fields are marked *