Running shell scripts, commands need root/su, how?
I've written a couple of shell scripts and some of the commands in them need root privileges. I've read somewhere to never put the root or super user's password in a script because it's not encrypted. How do I run these commands as root/su in a script?
|
sudo scriptname
|
oops, sorry. They won't be ran manually, they'll be kicked off by cron. So it has to be automated, no user input required.
|
You can configure sudo to not require a password for specific commands.
Evo2. PS. However, if you do this for the script, make very sure that the script is only writable by root. A slightly better approach is just to use sudo for the specific commands where root is needed, not for the whole script. |
hmmm. how about "sudo crontab -e"? won't that make my scripts run with root privileges?
|
@ digity - you are correct.
Just add it to root's crontab instead of yours. Running from inside su or sudo can confuse crontab (see man crontab) so: sudo -i crontab -e |
All times are GMT -5. The time now is 06:22 AM. |