[SOLVED] Data pipe lost when using ssh in shell script
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
Send ssh commands to random IPs ? What is your intentions lol
Yeah I wondered about the random part. I assume when they say random they mean 'randomly selected from a pool of IP addresses belonging to machines which I can log in to using ssh key authentication'. Perhaps too large an assumption. Can't think what they mean otherwise though. I mean no one would really expect to log in to machines by just randomly generating IP addresses... would they...?
The problem is due to a feature of the remote command execution through ssh: the standard input coming from the pipe and feeding the while read loop, becomes the standard input of the remote commands. Once the commands are executed, ssh sends back a SIGTTIN signal to stop the input flow. The side effect is that the standard input of the loop is broken and no further iteration is performed.
To avoid this, add option -n to each ssh command in the script: it will redirect the standard input from /dev/null and will protect the actual input of the loop from the SIGTTIN signal.
If you run IPGen.exe what does the output look like?
One IP on each line.
Quote:
Send ssh commands to random IPs ? What is your intentions lol
Quote:
I assume when they say random they mean 'randomly selected from a pool of IP addresses belonging to machines which I can log in to using ssh key authentication'.
Exactly.
Quote:
Originally Posted by colucix
The problem is due to a feature of the remote command execution through ssh: the standard input coming from the pipe and feeding the while read loop, becomes the standard input of the remote commands. Once the commands are executed, ssh sends back a SIGTTIN signal to stop the input flow. The side effect is that the standard input of the loop is broken and no further iteration is performed.
To avoid this, add option -n to each ssh command in the script: it will redirect the standard input from /dev/null and will protect the actual input of the loop from the SIGTTIN signal.
Dear colucix thank you very much. That little "-n" did the trick. Also thanks for detailed info about SIGTTIN. I learned something new.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.