Shell script implements code sharing for copying files to multiple servers _linux shell

Source: Internet
Author: User

In a multiple-machine cluster environment, often faced with the modification of the configuration file after copying to multiple servers, the traditional implementation of the SCP is troublesome, so write the following shell script, you can copy the specified files to multiple machines.

Use the method See Help section code.

 #!/bin/bash help () {cat << help--------------Help-----------------------
    -This shell script can copy file to many computers.
    Useage:copytoall filename (full path form/home) targetpathfrom/username ip1 ip2 ip3 ....  example:copytoall/home/casliyang/hadoop-2.2.0/etc/hadoop/core-site.xml/home/casliyang/hadoop-2.2.0/etc/hadoop/
 Casliyang 192.168.0.5 192.168.0.6 192.168.0.7 192.168.0.8------------------------------------------help exit 0 currentdate=$ (date +%y-%m) echo $currentdate "Execute Copytoall" if [$ =]; Then help exit 0 fi file=$1 shift targetpath=$1 shift user=$1 shift tempip=0 if [f $file]; Then while [$#-GT 0]; Do tempip=$1 shift SCP $file ${user}@${tempip}:${targetpath} did else echo "wrong file! "Exit 0 fi 
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.