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
# 8  
Old 12-24-2010
create these scripts and make them executable. it should give you a good starting point. add error logic as needed

server1.ksh
Code:
#!/usr/bin/ksh

USER2=foo
SERVER2=bar

uptime=$(/usr/bin/ssh $USER2@$SERVER2 /path/to/server2.ksh)
# check $? for ssh errors

echo "uptime: $uptime"

server2.ksh
Code:
#!/usr/bin/ksh

nodeName=blah
/opt/OV/bin/snmpget -r 0 -t 60 $nodeName system.3.0 | cut -d: -f3-5


then run it
Code:
ssh $SERVER1 /path/to/server1.ksh

# 9  
Old 12-24-2010
MySQL

In my earlier post when i said that i wanted to get it working, i meant, i wanted to know how to get the meta-character thingy working..

Yeah, and this(using 2 scripts) is the other way i implemented my script, and works like a charm, thanks for your help frank..

Wish you a Merry Christmas and a happy new year,
BlubSmilie
# 10  
Old 12-24-2010
try this.

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

This User Gave Thanks to frank_rizzo For This Post:
# 11  
Old 12-24-2010
MySQL

SmilieSmilieWorks nicely.. Could you explain why it wasnt workin earlier and what has been changed in this command?

Thanks a tonne,
BlubSmilie
# 12  
Old 12-24-2010
it has to do with the quoting and command substitution. using back ticks `` without single quotes was actually causing snmpget to be run on the current system. I simulated the same behavior with echo -n so you don't have to worry about that and also added quotes. it can get tricky and unmaintainable doing things like this.
# 13  
Old 12-24-2010
oks, will take ur advice on this.. THanks for your time, frank..

Regards,
BlubSmilie
# 14  
Old 01-26-2011
Hey Frank,
I have a smilar problem, where my ssh is not working when I am trying to do the su - user.
Code:
ssh -t -f 172.18.197.41 "su - d_od 'ls -lrt /usr/dev/ods|head -10'"

It is working fine if I am not doing the su:
Code:
ssh 172.18.197.41 "ls -lrt /usr/dev/ods|head -10"

Can you pls helpme with this.

Thanks
Ajay
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