LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-26-2004, 12:26 PM   #1
kaloyer
Member
 
Registered: Jun 2004
Location: Tucson, AZ, USA
Distribution: Arch Linux 0.7
Posts: 52

Rep: Reputation: 15
Angry Need to run shell script as root


OK, I need a shell script to run as root, but I can't get commands to pass over from the regular user to root. I did the su, but the script doesn't finish until root exits. Does anyone know a workaround?
 
Old 06-26-2004, 12:33 PM   #2
kaloyer
Member
 
Registered: Jun 2004
Location: Tucson, AZ, USA
Distribution: Arch Linux 0.7
Posts: 52

Original Poster
Rep: Reputation: 15
I have a solution now, but I was wondering if anyone has anything better. I can do
Code:
su -c "sh newscript"
but i want this to be one file. Any ideas?
 
Old 06-26-2004, 12:42 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
You can add at top of script
if [ `id -u` != 0 ]; then exec su -c "sh $0"; fi

Last edited by keefaz; 06-26-2004 at 12:45 PM.
 
Old 06-26-2004, 05:22 PM   #4
kaloyer
Member
 
Registered: Jun 2004
Location: Tucson, AZ, USA
Distribution: Arch Linux 0.7
Posts: 52

Original Poster
Rep: Reputation: 15
hey thancks! that fixed the whole thing.
 
Old 06-27-2004, 09:01 AM   #5
Eran
LQ Newbie
 
Registered: Jun 2004
Posts: 2

Rep: Reputation: 0
You can also try the 'sudo' command.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Run shell script as root automatically elempoimen Linux - Software 8 06-20-2010 01:24 AM
allow sudo for www user to run root shell script cccc *BSD 12 07-23-2005 03:48 PM
How to run SHELL script pito Linux - Newbie 4 12-17-2004 03:05 AM
Shell script to run pl/sql script. colly Linux - General 1 09-09-2004 06:49 AM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration