Linux shell executes commands or scripts (SSH) on a remote computer

Source: Internet
Author: User

 

 Large data platform often set up to design multiple nodes of the cluster needs to be unified deployment, this design to the daemon or deployment script at different nodes, if it can be on the master machine, unified execution script, one-time start of the entire Cluster service, feel very nice. Because, share the following content:

Prerequisites:

 Configure SSH password-free login

for a simple command:

If you are executing several commands on the remote node:

SSH " cd/home; LS "

 Note the point:

    1. Double quotes, must have. If you do not add double quotes, the second LS command executes locally
    2. Semicolon, separated by a semicolon between two commands
for ways to execute scripts remotely:

  Some remote execution of the command content, a single command can not be completed, consider the scripting way to implement:

#!/bin/bashssh [email protected] >/dev/null 2> &1 < < Eeoo Cd/hometouch Abcdefg.txtexiteeooecho done!

    1. << Eeoo,ssh until the end of the Eeoo, Eeoo can be modified to other forms.
    2. Redirection is intended to not show the remote output.
    3. Before the end, add exit to exit the remote node

My sample code:

#!/Bin/Bashsource/home/config.sh/home/start-xxx.py Echonode LocalOK
#kill process no Neededps x|Grep' XXX' |Grep-V grep|Awk'{print $}'|Xargs-LKill -9SSH Root@XXX141 > /Dev/NULL 2>&1 <<Eeooffsource/home/config.sh/home/start-xxx.pyexitEeooffecho xxx141done!
SSH [email protected] >/dev/null 2>&1 << eeooffsource/home/config.sh/home/start-xxx.pyexit  Eeooffecho xxx142 done!  

Linux shell executes commands or scripts (SSH) on a remote computer

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.