Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

need to do multiple SSH hops using Perl script.

8 views
Skip to first unread message

pradeep nair

unread,
Nov 20, 2009, 4:57:32 AM11/20/09
to
The script must:

1. ssh to system A ,from there ssh to system B & from there ssh to
system C.
2. At system C need to connect to a DB and execute few queries and
create an output file
3. The outfile should be SCpied to Sytem A

Using command ssh -L -T, I am able to end up at System C with perl
command system. Am stuck there as in the output the cursor remains at
system C but I need the script to perform step 2 and 3 as mentioned
above.


Thanks in advance,
pRADEEP

Message has been deleted

smallpond

unread,
Nov 20, 2009, 9:10:02 AM11/20/09
to

You should be using Net::SSH.

Josef Moellers

unread,
Nov 20, 2009, 9:13:46 AM11/20/09
to pradeep nair

I'd use Expect.
Note that it's not for the faint of heart ;-)

Josef
--
These are my personal views and not those of Fujitsu Technology Solutions!
Josef M�llers (Pinguinpfleger bei FTS)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html

Andrew DeFaria

unread,
Nov 20, 2009, 12:27:18 PM11/20/09
to
On 11/20/2009 02:57 AM, pradeep nair wrote:
The script must:

1. ssh to system A ,from there ssh to system B & from there ssh to system C.
2. At system C need to connect to a DB and execute few queries and create an output file
3. The outfile should be SCpied to Sytem A
Is there a particular reason why you cannot connect to the DB from system B or system A for that matter? Or is there a particular reason why you cannot ssh directly from system A -> system C? I mean why go through these hoops when databases are accessible over the net?

Using command ssh -L -T, I am able to end up at System C with perl command system.
What's a "perl command system"?

Am stuck there as in the output the cursor remains at system C but I need the script to perform step 2 and 3 as mentioned above.
I assume you have some way of doing this by hand. IOW, you can ssh into system C and then connect to the DB (how?) and execute a few queries creating an output file. How are you currently getting from system A -> system B -> system C programmatically in order to get to the "cursor" on system C? I assume Expect (perhaps not). If so then you would use Expect to issue the same commands you would have done by hand.
--
Andrew DeFaria
For Sale: Parachute. Only used once, never opened, small stain.

Martijn Lievaart

unread,
Nov 21, 2009, 10:21:23 AM11/21/09
to
On Fri, 20 Nov 2009 01:58:41 -0800, pradeep nair wrote:

> The script must:
>
> 1. ssh to system A ,from there ssh to system B & from there ssh to
> system C.
> 2. At system C need to connect to a DB and execute few queries and
> create an output file
> 3. The outfile should be SCpied to Sytem A
>

If the script is on host C:
ssh A ssh b ssh C <script> >outfile

If the script is on host A:
cat <script> | ssh A ssh b ssh C sh - >outfile

So first make a script on C that works, then try to execute it via ssh

HTH,
M4

0 new messages