SSH traversal IPs for connection

Source: Internet
Author: User

Today production to batch connect the server and execute the command: Write all the IP to a iplist file, then use while read and for to traverse the stitching SSH command found two problems: SSH connection parameter-N and while read and for read the difference

Script

IPList

192.168.4.12

192.168.4.13

192.168.4.14


tongjidf.sh

#!/bin/bash

cmd= "Df-m | grep app "

While Read line

Do

SSH [email protected]${line} $cmd

Done <./iplist

The results of the execution found that only one address was connected 192.168.4.12, the following address was not executed

and changed it into a for.

#!/bin/bash

Cmd= "Df-m|grep App"

For IPs in ' Cat IPList '

Do

SSH [email protected]${line} $cmd

Done

This script can be implemented by connecting all of the above addresses and then executing commands.

Finally found a saying that is for is a row of reads, while the while read line is a read into the memory

The second is that SSH reads the local content by default, and the-n parameter blocks it, but reads it from/dev/null/, so that SSH is connected in the form of a while-read line

- n redirects stdin from/dev/null (actually, prevents reading from stdin).  This must was used when SSH was run in the background. A
Common trick is the use of this to run X11 programs in a remote machine. For example, Ssh-n shadows.cs.hut.fi Emacs & would start
An emacs on shadows.cs.hut.fi, and the X11 connection'll be automatically forwarded over an encrypted C  Hannel. The SSH pro-
Gram'll is put in the background. (This does isn't work if SSH needs to ask for a password or passphrase; see also The-f








SSH traversal IPs for connection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.