Operate command lines on multiple hosts at the same time

Source: Internet
Author: User
Tags hadoop fs

I have an inch

Let the command line appear first:

Cat conf/slaves | xargs echo | sed-e "s //,/g" |

Sed-e "s/^ (. *) $/pdsh-f 200-w" 1 "" jps | grep JobShell | cut-f1-d | xargs kill-9 then /" |

/Bin/bash

The first line is mainly to combine the slave of a row into a single row, separated by commas (,). The sed of the first line can also be used by tr.

The purpose of the second line is to consolidate the pdsh command line. This is a tool that operates multiple machines at the same time. The pdsh-w is followed by the node list, that is, the file list of the row just now. A group of command lines are enclosed in quotation marks. These command lines are sent to each computer for execution. The preceding line actually kills the JobShell Java Process on each node. Finally, in the third line, the command line synthesized above is handed to shell for execution.

This command line looks long, but it is not actually complicated. There is also a variant version.

Cat conf/slaves | xargs echo | sed-e s //,/g |

Sed-e "s/^ (. *) $/pdsh-f 200-w" 1"
For I in 'seq 2001 2100 ';
Do/share/home/testhdp/hadoop-0.19.2/bin/hadoop fs-touchz 'uname-n'. $ I;
Done/"|

/Bin/bash

The middle line is broken into four lines, but the line should not be broken. The first part of this line is the same as the above. The key to the next step is how to put the back quotes out, instead of being replaced by direct variables in the local shell on the spot, the actual processing is very simple-put the command line in single quotes, of course, all kinds of quotation marks and the $ before I need a backslash, otherwise, it will be explained by the current shell before being sent to bash. After such processing, the reverse quotation marks will be sent to each machine, and the shell on that machine will open the reverse quotation marks and replace the variables will also be carried out remotely.

Well, this command is not very complicated. If you are interested, you can modify it and give feedback.

Related Article

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.