Login
Search
Welcome to the iTechForums.
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
To register now click here.
Latest Threads
Advertisements
Forum Statistics
Threads:
Posts: 2
Members:
Number of Users Online:
Welcome to our newest member,
Reply
 
Thread Tools Display Modes
  #1  
Old 05-12-2008, 08:15 AM
Saurav Saurav is offline
Junior Member
 
Join Date: May 2008
Posts: 4
Default

Help with using sudo in a unix shell script?


I am trying to use sudo command in unix shell script. Its that it will do sudo and then search a file in the directory and then come out of the sudo account

my account = saurav

here is the script code
********************************
sudo -u abcd -s
cd /application/somefolder/
id
grep jdbcracle:thin server.properties

********************************************

now how do i come out of the account to which i sudo, i can always use CTRL+D / ctrl + x from the prompt, but what should be used in the script to get out of the account back to my own account.

which is from abcd to saurav
Well i cannot change the sudoers property, since i am not the admin/root

This is the only way to work out in my environment, and using exit in the script just closes the script it doesnt come out of the sudo user.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 05-12-2008, 08:16 AM
Eric V Eric V is offline
Junior Member
 
Join Date: May 2008
Posts: 9
Default

why must you sudo as a user, then change directories, then check the id, then do a grep? shouldn't you do it all in one go?

if you setup your sudoers file correctly, the above could be accomplished with

sudo grep jdbcracle:thin /app/folder/server.properties

If you really need to use your version, try
exit

or else try su saurav



Let me know if that works or not, and feel free to ask more questions
-Eric
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unix shell programming question? Sachin V UNIX 1 05-06-2008 01:47 PM
Need help on Unix script? Try1 UNIX 0 05-06-2008 01:46 PM
which of them is Multi User operating System? (1) MS DOS (2) DOS SHELL (3)UNIX (4)... waqas UNIX 3 05-06-2008 12:53 PM
Question in UNIX Shell Programming? shipudenPai UNIX 1 05-06-2008 12:31 PM
A unix shell script has to check for a file in a folder, once every 5 mins? preethi1682 UNIX 1 05-06-2008 09:32 AM

Your Ad Here

All times are GMT. The time now is 11:28 AM.