LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-15-2009, 05:15 PM   #1
ne00
LQ Newbie
 
Registered: Apr 2009
Posts: 9

Rep: Reputation: 0
Possible to pass an argument from one shell env to another?


So I have two commands.

become admin #becomes another user
ssh spc1 #ssh into another server

I'm trying to combine the two commands in a script I'm writing. Problem is that once become admin is executed, the shell environment changes and thus the ssh command part is not run because I'm placed on a new environment (that's my guess).

Is there any way I can pass the ssh command into the new environment so when I become another user the ssh command is executed for that user?

Regards

David
 
Old 04-15-2009, 05:47 PM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,067

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
I think the problem is that when you execute 'su admin' this command is executed in its own subshell. After the command you are dropped back into you script and you lost everything which was done in that subshell. It is almost the same as what you say, the result is equal anyway.

But why not execute you entire script as admin is you need admin privileges on the box you are running that script?

You can also try to add the ssh command to the 'su' command:
Code:
su admin -c ssh
It is not fully clear to me why you use the command 'become'. Anyway you would have to supply a password isn it?

And if you need admin privileges on the box you are connecting to, you can use:
Code:
ssh -l another_user myhost.com
Many boxes have excluded root from ssh access, so you would have to ssh first to the host, and then become admin.

If you want to script your ssh commands on the other box as well that can become complicated. You'd have to write a so-called here document: http://tldp.org/LDP/abs/html/here-docs.html#HEREDOCREF

jlinkels
 
Old 04-15-2009, 06:23 PM   #3
ne00
LQ Newbie
 
Registered: Apr 2009
Posts: 9

Original Poster
Rep: Reputation: 0
Hi, thanks for the suggestions.

It's not really an admin of the local machine but an admin to access the other local environments available. When I execute the become admin command I'm not prompted for a password I just become admin so I can access the other environments through the ssh command.

Executing the two commands from the command line one at a time is fine, but like you said about the different sub shells is where I'm running into the problem of having it executed in a script.
 
Old 04-15-2009, 06:34 PM   #4
ne00
LQ Newbie
 
Registered: Apr 2009
Posts: 9

Original Poster
Rep: Reputation: 0
hahaha

Ok...looked at the help files of become and figured it out.

Basically it's...

Code:
become <user>[@<host>]
seems to replace the two separate commands of become and ssh.
 
Old 04-15-2009, 09:19 PM   #5
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,067

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
Cool, but what program is become?

Some special script on your machine? I googled for the man page but it was not there.

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I pass command to gnome-terminal as an argument? crasywolf Linux - Newbie 5 05-11-2010 09:00 AM
Pass argument between php scripts gandalf_the_grey Linux - Newbie 1 02-03-2006 02:53 PM
How to pass an argument to DHCPCD ? shazam75 Linux - Networking 3 02-27-2005 10:34 AM
PHP pass argument to shell script monzter Programming 2 08-14-2004 06:16 AM
How to pass env variable to KDE? koyi Linux - General 0 09-03-2003 03:29 AM


All times are GMT -5. The time now is 03:48 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration