The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
shell script to execute user command redtiger Shell Programming and Scripting 1 04-30-2008 03:53 PM
how to execute a batch script from shell script lakshmis10 Shell Programming and Scripting 1 10-17-2007 09:43 AM
How to restrict the number of commands user can execute rockysfr Shell Programming and Scripting 1 07-03-2007 10:53 AM
script execute or no execute Kespinoza97 Shell Programming and Scripting 4 06-23-2007 06:27 AM
Maint user cannot execute ping command kabeer_n UNIX for Dummies Questions & Answers 3 10-23-2006 08:01 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-10-2007
Registered User
 

Join Date: Sep 2007
Posts: 6
Execute internal script as different user

I have a script that I must run as user X and need to send the results to a different server as user Y (sftp). User Y has been set up to not require password authentication between the 2 servers. I would prefer to keep these in a single script, as our operations might have to run it from time to time and I would prefer to keep things simple.

Another thought was to have 2 scripts that poled a status file to see "whose" turn it was to execute.

Any suggestions?

Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-10-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
What is supposed to be executed by Y?

as user X

Code:
....

sftp ... Y@server <<EOF
.....
EOF

.....
Reply With Quote
  #3 (permalink)  
Old 09-11-2007
Registered User
 

Join Date: Sep 2007
Posts: 6
Yes, sftp needs to be run as user Y. The main script is a start/stop process for a web based application (separate app and web servers). All the processes must be started or stopped as user X, but user Y must be used to send results to the other server detailing basically whose turn it is to run.

[app server script]
start environment (x)
start rmi (x)
sftp web (y)
wait till app continue
start scheduler (x)

[web server script]
wait till web
start web (x)
sftp app continue (y)
Reply With Quote
  #4 (permalink)  
Old 09-11-2007
Registered User
 

Join Date: Sep 2007
Posts: 4
since everything else is run under user x, maybe you can just enclose the sftp command for user y in an su -c command
Reply With Quote
  #5 (permalink)  
Old 09-11-2007
Registered User
 

Join Date: Sep 2007
Posts: 6
I am also trying to keep from storing the password of the User Y on the system as well and user X is not root.
Reply With Quote
  #6 (permalink)  
Old 09-11-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Try this

script starts as X

script then does SSH to other system as Y using private key as follows...

Code:
echo this is running as X here
ssh -i identity Y@other <<EOF
echo this script part will run as Y on the other machine
EOF
echo this is back running as X here
Reply With Quote
  #7 (permalink)  
Old 09-12-2007
Registered User
 

Join Date: Sep 2007
Posts: 6
Ok. Iwill try that, but we initially had it setup as host-based authentication instead of public key. It is being changed to public key.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0