Powerful batch shell commands

Source: Internet
Author: User

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

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.