Help with executing multiple remote commands after multiple hops


 
Thread Tools Search this Thread
Operating Systems Solaris Help with executing multiple remote commands after multiple hops
# 1  
Old 12-16-2010
Help with executing multiple remote commands after multiple hops

Hi SSHers,

I have embedded this below code in my shell script..

Code:
 
/usr/bin/ssh -t $USER@$SERVER1 /usr/bin/ssh $USER2@S$SERVER2 echo uptime:`/opt/OV/bin/snmpget -r 0 -t 60 $nodeName system.3.0 | cut -d: -f3-5`

SSH to both these servers are public-key authenticated, so things run smoothly until it comes to the execution of the commands..

It gives me the follow output for the shell script..

Code:
ksh: /opt/OV/bin/snmpget:  not found
uptime:

I am assuming that the command '/opt/OV/bin/snmpget' got executed in the second server and since there is no such executable there the error comes up..
Also, in the final target server i get a valid output for the command '/opt/OV/bin/snmpget'..

Could someone help me execute both the commands on the same target server or tell me what i could be doing wrong here?

Thanks In Advance,
BlubSmilie
# 2  
Old 12-22-2010
I think your issue is a "shell substitution before execution" issue. (See this section 2.1 #4) Try this:
Code:
/usr/bin/ssh -t $USER@$SERVER1 /usr/bin/ssh $USER2@S$SERVER2 echo uptime:\\\`/opt/OV/bin/snmpget -r 0 -t 60 $nodeName system.3.0 | cut -d: -f3-5\\\`

The "snmpget" was executing on $SERVER1. That's where the "snmpget: not found" error came. By using the backslashes, the execution is delayed until access to $SERVER2 is authenticated.


HTH

Last edited by bluescreen; 12-22-2010 at 01:37 PM..
This User Gave Thanks to bluescreen For This Post:
# 3  
Old 12-23-2010
Re: Help with executing multiple remote commands after multiple hops

Thanks for your tip, bluescreen.. tried what you had asked me to, but that seems to fail.. Here's the output i got
Code:
 
cut: invalid character in range

I will try to change the shell script as per the tips provided in the link..


Wish you a Merry Christmas,
BlubSmilie..
# 4  
Old 12-23-2010
I got this to work:
Code:
$ ssh -t $SERVER1 /usr/bin/ssh $SERVER2 echo uptime: \\\`uptime \\\| cut -d: -f3-5 \\\`

Notice the "\\\" before the pipe. Sorry I forgot that in my previous post. Smilie
This User Gave Thanks to bluescreen For This Post:
# 5  
Old 12-23-2010
MySQL Re: Help with executing multiple remote commands after multiple hops

Thanks again bluescreen.. Would you by any chance have any link that isnt as detailed as the one you had sent?
I tried another method and implemented the above shell using two shell scripts, one which is a wrapper sitting in the source, the other does the main functionality, and sits in the First hop server.. This seems to work fine..

I will try escaping the pipes and see if that does any good.. Thanks once more mate..

Regards,
BlubSmilie
# 6  
Old 12-23-2010
i suggest writing simple scripts and then execute the scripts instead of battling with shell metacharacters. it will make your life much easier.
# 7  
Old 12-24-2010
Bug

Smilietrue, but just wanted to know how to get it working.. thats allSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

scp over multiple hops

Hi friends, I am trying to scp a file from server A to Server C via Server B (which is jump host) from Server A to Server B i have one pem key. from server B to server C I have different Pem key.. what I tried scp -r -o ProxyCommand="ssh -W %h:%p ec2-user@1.4.5.5 dmu.sh... (7 Replies)
Discussion started by: onenessboy
7 Replies

2. Shell Programming and Scripting

Ssh to multiple hosts and then run multiple for loops under remote session

Hello, I am trying to login to multiple servers and i have to run multiple loops to gather some details..Could you please help me out. I am specifically facing issues while running for loops. I have to run multiple for loops in else condition. but the below code is giving errors in for... (2 Replies)
Discussion started by: mohit_vardhani
2 Replies

3. Shell Programming and Scripting

Ssh multiple hops to execute commands with arguments

Hi I need to write a script to ssh through several hops (e.g. HostA-HostB-HostC-HostD), where Host A does not have direct assess to HostC ; HostB cannot access HostD directly. when I ssh 3 hops and run command with arg1, arg2 and redirect the output to a file, e.g. HostA> ssh -t HostB ssh -t... (3 Replies)
Discussion started by: chiensh
3 Replies

4. Shell Programming and Scripting

Executing multiple commands in a file at same time

Hi Am having file.ksh as below wc -l file1.txt wc -l file2.txt wc -l file3.txt wc -l file4.txt i want all the commands in this file to execute in same time please help Thanks in advance (1 Reply)
Discussion started by: ragu.selvaraj
1 Replies

5. Shell Programming and Scripting

Executing multiple ssh commands inside a shell simultaneously

I would like to execute a commands in four different servers through ssh at a single instance(simultaneously). Below are the details with examples, ssh user1@server1 "grep xxxx logs" ssh user1@server2 "grep xxxx logs" ssh user1@server3 "grep xxxx logs" Each statement will take some... (4 Replies)
Discussion started by: Amutha
4 Replies

6. IP Networking

http over ssh tunnel using multiple hops

Hello, I got an application on a linux server that I would like to access using https and a URL. I would like to create a ssh tunnel. But, let's say the app is on box C, but box C can only be accessed through box B, that can be accessed only through box A. I would like to create the ssh tunnel... (0 Replies)
Discussion started by: Pouchie1
0 Replies

7. Shell Programming and Scripting

perform 3 awk commands to multiple files in multiple directories

Hi, I have a directory /home/datasets/ which contains a bunch (720) of subdirectories called hour_1/ hour_2/ etc..etc.. in each of these there is a single text file called (hour_1.txt in hour_1/ , hour_2.txt for hour_2/ etc..etc..) and i would like to do some text processing in them. Each of... (20 Replies)
Discussion started by: amarn
20 Replies

8. Shell Programming and Scripting

Need help with executing multiple commands in remote machine

Hi, I work on a jumpserver and I wrote a script to transfer a file from source server to destination server. #!/bin/ksh echo "\nEnter the file name:\n" read name echo "\nSelect the Source server\n" echo "1. ODS PROD " echo "2. ODS DROPBOX" echo "3. ODS STE" echo "4. ODS STE DROPBOX"... (6 Replies)
Discussion started by: ajayakunuri
6 Replies

9. Shell Programming and Scripting

SSHing with multiple hops

Hi, I have got a shell script, which fails to run properly.. I am getting the following error: "Pseudo-terminal will not be allocated because stdin is not a terminal. Permission denied (gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive)." I SSH to the machine and then run the... (1 Reply)
Discussion started by: LinuxUser2008
1 Replies

10. Shell Programming and Scripting

Automating executing commands on multiple tapes and changing (loading) them

The thing that we need to be able to do is: - Scanning tapes from failed backup jobs with bscan (a bacula command) - loading the next tape with the mtx command Bscan does unload tapes but does not load them. Bscan comes with this message when it's done with a tape: Mount Volume... (0 Replies)
Discussion started by: Tr00tY
0 Replies
Login or Register to Ask a Question