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 |
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.
|
 |
09-24-2002, 09:37 AM
|
#1
|
Member
Registered: Feb 2002
Location: Jerusalem, Israel
Distribution: Fedora Core 3
Posts: 154
Rep:
|
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
|
|
|
09-24-2002, 09:47 AM
|
#2
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
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?
|
|
|
09-24-2002, 10:02 AM
|
#3
|
Member
Registered: Feb 2002
Location: Jerusalem, Israel
Distribution: Fedora Core 3
Posts: 154
Original Poster
Rep:
|
yes actually :-)
I'll try the -c option. thanks.
|
|
|
09-24-2002, 10:48 AM
|
#4
|
Senior Member
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552
Rep:
|
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.
|
|
|
09-24-2002, 10:53 AM
|
#5
|
Senior Member
Registered: Sep 2002
Location: Philippines
Distribution: Slackware, RHEL&variants, AIX, SuSE
Posts: 1,127
Rep:
|
why not use sudo?
|
|
|
09-25-2002, 02:34 PM
|
#6
|
Member
Registered: Feb 2002
Location: Jerusalem, Israel
Distribution: Fedora Core 3
Posts: 154
Original Poster
Rep:
|
what's sudo?
|
|
|
09-25-2002, 03:44 PM
|
#7
|
Member
Registered: Sep 2002
Location: somewhere
Distribution: gentoo
Posts: 123
Rep:
|
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.
|
|
|
09-25-2002, 04:20 PM
|
#8
|
Member
Registered: Feb 2002
Location: Jerusalem, Israel
Distribution: Fedora Core 3
Posts: 154
Original Poster
Rep:
|
thanks again 
|
|
|
All times are GMT -5. The time now is 06:54 AM.
|
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
|
|