Data pipe lost when using ssh in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Data pipe lost when using ssh in shell script
# 1  
Old 01-31-2012
Question Data pipe lost when using ssh in shell script

Hi,

I want to do SSH on many different machines and then run some commands on them. A binary application randomly generates IP addresses and my script will take care of doing SSH.

Code:
$ ./IPGen.exe | ./myScript.sh

my script looks like this:

Code:
while read line; do
      result1=$(ssh $line 'LinuxCommand1') &
      result2=$(ssh $line 'LinuxCommand2') &
      result3=$(ssh $line 'LinuxCommand3') &
      wait;
      echo "$result1 - $result2 - $result3";
done

The problems are:
1- The while loop ends after first round!!!
2- All variables (result1, result2, result3) are empty.



I tried to search the forum before posting but I really didn't know what should I search for?!
# 2  
Old 01-31-2012
If the ./IPGen.exe is generating multiple ip addresses, then you need to use it like

Code:
 
./IPGen.exe | while read ip; do ./myScript.sh $ip; done

In the shell script,

Code:
 
echo $1 | while read line; do
 result1=$(ssh $line 'LinuxCommand1') &
      result2=$(ssh $line 'LinuxCommand2') &
      result3=$(ssh $line 'LinuxCommand3') &
      wait;
      echo "$result1 - $result2 - $result3";
done

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 02-01-2012
Thanks itkamaraj

Also, I found another solution.
Usin "-n" with SSH will redirect output to /dev/null and SIGTTIN will not break the STDIN.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

The Shell lost the inverted comma in a nested ssh command

Hi, i want use this Comand for my psql request sh ssh -o StrictHostKeyChecking=no rootatemailaddress.de sudo psql -U postgres -c "select pg_terminate_backend(pid) from pg_stat_activity where datnam=\'$DB\';"'" but the shell lost the inverted comma for datnam=\'$DB\'. The request deliver... (2 Replies)
Discussion started by: peterpane007
2 Replies

2. Shell Programming and Scripting

How to pipe command output to shell script?

Hi Team, Need a help on how to pipe a command out put to a shell script. My shell script looks like below. cat shell_script #!/usr/bin/ksh input =$@ echo " we are inside the shell script" echo " here are the input parameters" .......................... .................. ... (11 Replies)
Discussion started by: gvkumar25
11 Replies

3. Homework & Coursework Questions

Lost in shell script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hey whats up everyone, Currently I'm stuck. In this question I have to use the following commands test, shift,... (7 Replies)
Discussion started by: AdamSahp
7 Replies

4. Shell Programming and Scripting

Using Named pipe in shell script

Hi, I want to use a Named pipe to get input from a growing file for further processing. When I prototype this scenario using a while loop, the data is not written to the named pipe. This the script I use to get data into the Named pipe: #!/bin/ksh mkfifo pipe while (( n <= 10 )) do echo... (2 Replies)
Discussion started by: sudvishw
2 Replies

5. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

6. Post Here to Contact Site Administrators and Moderators

My shell pipe 2 multipipes thread is lost ?

Hi, yesterday I have got reply in my thread how to redirect shell pipe to 2 pipes. I would read that answer once again, as my re.re. is also lost Jack (6 Replies)
Discussion started by: jack2
6 Replies

7. UNIX for Dummies Questions & Answers

New to shell script and lost....

I am really stuck on something I am sure you all will find simple. I am VERY new to shell scripting and I am trying to figure out how to do a or statement below. So if it = 11 or 31 then... if ; then Please keep in mind I do not know much on shell scripting and thank you in advance as... (8 Replies)
Discussion started by: LRoberts
8 Replies

8. Shell Programming and Scripting

Pipe data to shell script

Sorry about the noobish question but... How do I capture data thats piped to my script? For instance, ls -al | myscript.sh How do I access the output from ls -al in myscript.sh? (3 Replies)
Discussion started by: tomjones07
3 Replies

9. Filesystems, Disks and Memory

Lost Data Lost Admin

First time so excuse my ignorance please. I may not be accurately describing the issue. I have inherited a small lab mostly SUN V120s. We lost power and are trying to recover. Nope no backups... The primary issue I have is 1 box is an Oracle Server. It has 2 36Gb harddrives. I am able to... (3 Replies)
Discussion started by: murphsr
3 Replies
Login or Register to Ask a Question