LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 01: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, 01: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, 01:42 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
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 01:45 PM.
 
Old 06-26-2004, 06: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, 10:01 AM   #5
Eran
LQ Newbie
 
Registered: Jun 2004
Posts: 2

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 02:24 AM
allow sudo for www user to run root shell script cccc *BSD 12 07-23-2005 04:48 PM
How to run SHELL script pito Linux - Newbie 4 12-17-2004 04:05 AM
Shell script to run pl/sql script. colly Linux - General 1 09-09-2004 07:49 AM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 11:23 PM

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

All times are GMT -5. The time now is 09:52 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration