Sponsored Content
Top Forums Shell Programming and Scripting Using ssh command inside a script Post 302495520 by mick_000 on Thursday 10th of February 2011 01:01:49 PM
Old 02-10-2011
Question Using ssh command inside a script

Hi,

I have a script file in server A. Inside the script file, I first have a ssh command that will connect to a remote server B. In the same script file itself, I have a sequence of commands that has to be run in server B. I am embedding these commands in the script file that I have in server A. When i run the script file in server A, it first gets connected to server B but nothing happens for sometime after which i get Connection timeout and some error in the command.

Is there a restriction in the kind of commands that can be executed in server B from server A with the scenario as mentioned above?

Instead of a script file, when i execute the commands one by one in console in server B it is getting executed. ie) first i connect to server B from server A using ssh and then run the commands one by one in server B. I want these commands to be placed in a script file and executed from server A.

Kindly provide a solution.

Thanks in advance.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ssh not ending (sometimes) from inside a script, why?

Okay I have this script file that runs from cron and most the time it works just find. Except every so often one of the three ssh commands I have in it just doesn't know it's done and that of course causes the whole thing to hang! The ssh command has executed. I can tell this because the command... (1 Reply)
Discussion started by: stilllooking
1 Replies

2. Shell Programming and Scripting

looping a array inside inside ssh is not working, pls help

set -A arr a1 a2 a3 a4 # START ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS integer j=0 for loop in ${arr} do printf "array - ${arr}\n" (( j = j + 1 )) j=`expr j+1` done EOS # END ========= this is not giving me correct output. I... (5 Replies)
Discussion started by: reldb
5 Replies

3. Shell Programming and Scripting

Problem using ssh inside script

Hi, When runnin the following script it complte successfully with out any problem #!/bin/sh SERV="crm1" for s in $SERV do export WebLogicSessions=`ssh psoft@$s "cd /software/psoft/scripts ; ./getweblogicsessions.sh crm1 8001 PIA | awk '{print $1}' ` echo "Checking number of... (0 Replies)
Discussion started by: yoavbe
0 Replies

4. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

5. Shell Programming and Scripting

How to monitor a command inside shell script

Hi All, Is there any way to monitor a command inside shell script ? I have a script inside which I have a tar command which zips around 200GB data. tar zcvf $Bckp_Dir/$Box-BaseBackup-$Day.tar.gz * --exclude 'dbserver_logs/*' --exclude postmaster.pid --exclude 'pg_xlog/*' I want to... (3 Replies)
Discussion started by: sussus2326
3 Replies

6. Shell Programming and Scripting

Command timeout from inside script.

Hi, I've written a very robust script to get an external IP address from 'behind' a router. It uses many web pages randomly choosing which one/ones to use at run time. The "fetch the web page containing the IP address" is handled by either wget or curl both of which have their 'max time for the... (6 Replies)
Discussion started by: gencon
6 Replies

7. Shell Programming and Scripting

Issue with ls command inside script

Hi , DIR1 has only one file with .txt extension , trying to get the size of that file using the following script #!/bin/ksh foldr_1="/etc/DIR1" #echo "$foldr_1" sze_fdr1=$(ls -ltr foldr_1/*.txt |awk '{ print $5 }') echo "$sze_fdr1" After executing the above script getting... (1 Reply)
Discussion started by: smile689
1 Replies

8. Shell Programming and Scripting

While loop breaking when using "ssh" command inside

Hi , I am trying to read a list of hosts from a config file and trying to get file list from that host. For this I have used one while loop. cat "$ARCHIVE_CFG_FILE" | sed '/^$/d' | sed '/^#/d' | while read ARCHIVE_CFG do SOURCE_SERVER_NAME=`echo "$ARCHIVE_CFG" | awk -F '|' '{ print... (2 Replies)
Discussion started by: Anupam_Halder
2 Replies

9. UNIX for Advanced & Expert Users

Run awk command inside ssh

I am trying to run an awk command inside of ssh and it is not working. These are AIX servers. for i in `cat servers`; do ssh $i "/bin/hostname; df -g | awk '/dev/ && $4+0 > 70'"; done server1 server2 server3 server4 I also tried these two methods and they did not work. It just seemed... (5 Replies)
Discussion started by: cokedude
5 Replies
SSH-ARGV0(1)						    BSD General Commands Manual 					      SSH-ARGV0(1)

NAME
ssh-argv0 -- replaces the old ssh command-name as hostname handling SYNOPSIS
hostname | user@hostname [-l login_name] [command] hostname | user@hostname [-afgknqstvxACNTX1246] [-b bind_address] [-c cipher_spec] [-e escape_char] [-i identity_file] [-l login_name] [-m mac_spec] [-o option] [-p port] [-F configfile] [-L port:host:hostport] [-R port:host:hostport] [-D port] [command] DESCRIPTION
ssh-argv0 replaces the old ssh command-name as hostname handling. If you link to this script with a hostname then executing the link is equivalent to having executed ssh with that hostname as an argument. All other arguments are passed to ssh and will be processed normally. OPTIONS
See ssh(1). FILES
See ssh(1). AUTHORS
OpenSSH is a derivative of the original and free ssh 1.2.12 release by Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. Jonathan Amery wrote this ssh-argv0 script and the associated documentation. SEE ALSO
ssh(1) Debian Project September 7, 2001 Debian Project
All times are GMT -4. The time now is 06:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy