SCIENTIFIC-LINUX-USERS Archives

April 2014

SCIENTIFIC-LINUX-USERS@LISTSERV.FNAL.GOV

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Howard, Chris" <[log in to unmask]>
Reply To:
Howard, Chris
Date:
Tue, 29 Apr 2014 19:27:01 +0000
Content-Type:
text/plain
Parts/Attachments:
text/plain (46 lines)
You can use the suid permissions bit.
But be very careful to not let your script be hijacked.

I think there might be an option to the "su" command which
will let you run a script as another user.  You can
then split your script into two parts, have the first part
do things and then call 

su -c power-user  "/home/bin/newscript"


Something like that.  My syntax is probably bad.



-----Original Message-----
From: ToddAndMargo [mailto:[log in to unmask]] 
Sent: Tuesday, April 29, 2014 1:20 PM
To: Scientific Linux Users
Subject: How do I elevate in a script?

Hi All,

I have a bash script that need to be run as root.
In the script, I check to see if it is running as
root and flag the user to run appropriately.

Is there a way to use "su" to prompt for the password
and continue the script if successful? (I would test for
$? after the prompt.)

Currently "su" will just open a new shell as root.

I can run a command inside "su", but what about the
other 200 lines of code?  :'(

Many thanks,
-T


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ATOM RSS1 RSS2