Powerful batch shell command 1. First, rsh or ssh must be normal in the environment. 2. Configure nodes (all managed node hostnames). 3. Script # cat dsh #! /Bin/sh command =$ @; for I in 'cat. /nodes | grep-v ^ # 'do echo $ I; rsh $ I "$ command"; done command =@ @ this line indicates execution. the command after/dsh is as follows :. /dsh ls-a $ @ that is, ls-a $0 is the bash file name $? Is the content of the return value $ * Of All location parameters of the previous command: it is the parameter that calls the bash shell. $ @ Is basically the same as above. Only "$ *" returns a string with multiple spaces. "$ @" Returns multiple strings. And $ # returns the number of parameters at all locations. The following is a for loop, which means that each node hostname in the nodes file is assigned to I, which is equivalent to converting nodes into a variable. The node in nodes is called when I is called. The following is a script played by a friend. Please refer to: the script file IFS is used to change the separator to press enter [root @ fangs sh] # cat w3.sh #! /Bin/bashnode = ". /hosts.txt "IFS = $ '\ n' # command = $ @ for I in 'cat $ node | grep-v" # "'Do port = 22 new_port = $ (echo $ I | awk '{print $2 }') if [! -Z $ new_port]; then port = $ new_port fi host =$ (echo $ I | awk '{print $1 }') echo-e "====== Host $ host \ tPort $ port ====" ssh-p $ port $ host $ @ echo-e "\ n" done after the script is completed, you also need to write a separate nodes node file. If the host ssh listening port is not 22, write the port after the host and separate it with a tab or space [root @ fangs sh] # cat hosts.txt192.168.1.150willbing.com 3700 to run it. result [root @ fangs sh] #. /w3.sh date-R ===== Host 192.168.1.150 Port 22 === Sat, 11 May 2013 18:13:45 + 0800 ====== Host willbing.com Port 3700 ==== Sat, 11 May 2013 18:07:51 + 0800