The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Logging into oracle or SQL from shell script manirsendhil Shell Programming and Scripting 2 04-10-2007 12:46 AM
Logging OWB mapping execution in Shell script npn Shell Programming and Scripting 1 11-16-2006 09:25 AM
Have a script running even with the shell logging out 435 Gavea Shell Programming and Scripting 4 09-20-2005 05:20 PM
logging in Shell script laila63 Shell Programming and Scripting 3 07-16-2004 06:50 PM
shell script error logging niamh UNIX for Dummies Questions & Answers 1 04-05-2004 12:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-08-2005
mgirinath mgirinath is offline
Registered User
  
 

Join Date: May 2005
Posts: 69
logging as su from script

Hi,

I am running a script where i need to run another command in a particular folder which I do not have access so I need
to login as su to that folder and run that script...what are the options I need so that I
can skip interactive mode ..here is what I tried..

#! /usr/bin/sh
./profile
su - u02 password # it does not take it this way...
cd /u02/inf
pmcmd -u $username -p $password -s $server.....
....

here my problems are
after executing the .profile it ececutes su and waits for password........

1) how should I enter the option su as i run the script from my ID specifying su password...
2) will the variables that are defined in my profile stay even though i do su and run command because
$username,$password,$server are in .profile.....

how should I use it...please help...
  #2 (permalink)  
Old 12-09-2005
aniseed's Avatar
aniseed aniseed is offline
Registered User
  
 

Join Date: Dec 2005
Location: Mumbai, India
Posts: 23
Quote:
Originally Posted by mgirinath
#! /usr/bin/sh
./profile
su - u02 password # it does not take it this way...
cd /u02/inf
pmcmd -u $username -p $password -s $server.....
....

here my problems are
after executing the .profile it ececutes su and waits for password........

1) how should I enter the option su as i run the script from my ID specifying su password...
2) will the variables that are defined in my profile stay even though i do su and run command because
$username,$password,$server are in .profile.....

how should I use it...please help...
1) su allows interaction only through the console, probably for security reasons. You might try using supassword | su loginname but I doubt if it will work correctly. Alternatively, you could try using sudo command.
http://www.uwsg.iu.edu/UAU/advcomm/sudo.html

2) As per the manual entry for su, if you want to retain the previous environment variables, your command will be
Code:
su username

and if you want to use the environment for the user you are changing to
Code:
su - username

  #3 (permalink)  
Old 12-09-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Please search the forums before posting. There are numerous examples where this question has been asked in the past.

Cheers
ZB
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0