LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-24-2002, 09:37 AM   #1
NGraphiX
Member
 
Registered: Feb 2002
Location: Jerusalem, Israel
Distribution: Fedora Core 3
Posts: 154

Rep: Reputation: 30
switching users in a script


A bash script question:

I'm trying to write a script that among other things has to have
root access at some point. so I wrote:

#!/bin/bash
echo "entering root.. "
su
echo "you are now root"
...

The problem is that after running "su" the rest of the script
dosn't execute . I guess this is because I switched users in the
middle. but anyway, is there a way a script can switch users,
and still continue running?
ThanX, NGraphiX
 
Old 09-24-2002, 09:47 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well firstly it's an amazingly bad idea to do somethign like this, BUT you can go along the lines of

su -c 'ls'

i presume you do understand why your script fails completely?
 
Old 09-24-2002, 10:02 AM   #3
NGraphiX
Member
 
Registered: Feb 2002
Location: Jerusalem, Israel
Distribution: Fedora Core 3
Posts: 154

Original Poster
Rep: Reputation: 30
yes actually :-)
I'll try the -c option. thanks.
 
Old 09-24-2002, 10:48 AM   #4
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
When you su in the script you are jumping into another shell. The commands after the su won't get executed (and probably fail due to insuffient privelages) until after you exit from the su. I'd recommend either using the -c switch or su'ing before running the script.
 
Old 09-24-2002, 10:53 AM   #5
born4linux
Senior Member
 
Registered: Sep 2002
Location: Philippines
Distribution: Slackware, RHEL&variants, AIX, SuSE
Posts: 1,127

Rep: Reputation: 49
why not use sudo?
 
Old 09-25-2002, 02:34 PM   #6
NGraphiX
Member
 
Registered: Feb 2002
Location: Jerusalem, Israel
Distribution: Fedora Core 3
Posts: 154

Original Poster
Rep: Reputation: 30
what's sudo?
 
Old 09-25-2002, 03:44 PM   #7
RijilV
Member
 
Registered: Sep 2002
Location: somewhere
Distribution: gentoo
Posts: 123

Rep: Reputation: 15
http://open-systems.ufl.edu/docs/sudo/sudo.html

note, running shell scripts with root permissions that aren't solely owned by root and not readable by other users (or writable) is a Bad Idea.
 
Old 09-25-2002, 04:20 PM   #8
NGraphiX
Member
 
Registered: Feb 2002
Location: Jerusalem, Israel
Distribution: Fedora Core 3
Posts: 154

Original Poster
Rep: Reputation: 30
thanks again
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
switching users in gnome mherring02 Linux - Software 1 10-12-2005 09:22 PM
No Sound when switching Users Malacandra Linux - Hardware 6 02-23-2005 02:58 PM
Switching users... Tsion_avienu Red Hat 5 01-06-2005 12:29 PM
Switching users during bootup with hotkey?? BajaNick Linux - Software 2 11-21-2003 09:58 PM
switching users? MrPolite Linux - General 7 06-20-2002 03:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:54 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
Open Source Consulting | Domain Registration