Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-07-2010, 12:10 AM
|
#1
|
Member
Registered: Apr 2005
Posts: 105
Rep:
|
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?
|
|
|
01-07-2010, 12:12 AM
|
#2
|
LQ Guru
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211
Rep: 
|
sudo scriptname
|
|
|
01-07-2010, 12:20 AM
|
#3
|
Member
Registered: Apr 2005
Posts: 105
Original Poster
Rep:
|
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.
|
|
|
01-07-2010, 01:13 AM
|
#4
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
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.
Last edited by evo2; 01-07-2010 at 01:15 AM.
|
|
|
01-07-2010, 01:46 AM
|
#5
|
Member
Registered: Apr 2005
Posts: 105
Original Poster
Rep:
|
hmmm. how about "sudo crontab -e"? won't that make my scripts run with root privileges?
|
|
|
01-07-2010, 05:19 AM
|
#6
|
LQ Guru
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211
Rep: 
|
@ 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:25 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|