Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make a Bash file run as root in crontab? [closed]

Tags:

I need that Bash file to run periodically, and it must be as root.

Is that possible?

[root@file nutch-0.9]# locate crontab
/etc/crontab
/etc/sysconfig/crontab
/usr/bin/crontab
/usr/share/man/man1/crontab.1.gz
/usr/share/man/man1p/crontab.1p.gz
/usr/share/man/man5/crontab.5.gz
/usr/share/vim/vim71/syntax/crontab.vim
[root@file nutch-0.9]# 
like image 729
omg Avatar asked Jun 18 '09 22:06

omg


People also ask

Will a crontab run as root?

Like any other user, root has a user crontab. Essentially the same as any other user crontab, you are editing the root crontab when you run sudo crontab -e . Jobs scheduled in the root user crontab will be executed as root with all of its privileges.

How do I run a script as a root?

To give root privileges to a user while executing a shell script, we can use the sudo bash command with the shebang. This will run the shell script as a root user. Example: #!/usr/bin/sudo bash ....


1 Answers

Yes, just add it to the root users' crontab; run the crontab -e command.

The places cron stores its files can be a little bizzare, so use the crontab -e command which will make sure it's in the right place, and I believe it checks the syntax.

like image 87
whatsisname Avatar answered Sep 19 '22 20:09

whatsisname