CentOS: run crontab as root
Blogs20122012-10-18
CentOS: run crontab as root
Sometimes in a cron job, we have to write security directory such as /var/data/mysql/, in this case we need root permission.
There are several ways to run cron job by using root role. A simple solution is using ‘sudo’:
Normally as a normal user ‘demo’, I use sudo to borrow root permission by adding entry in /etc/sudoers with ‘nopasswd:all’. Similarly, in this case, we need to set sudo option in /etc/sudoers.
1. $ sudo vi /etc/sudoers:
Defaults requiretty
Defaults:demo !requirettyAfter the setting, we can sudo directly in crontab, without extra-declaration:
2. $ crontab -e
*/10 * * * * sudo /usr/bin/indexer -c $HOME/etc/file.conf --rotate delta --quietindexer will update /var/data/mysql directory every 10 minutes by using root permission. This works fine.
