Shell Project-Distribution system-build file distribution system

Source: Internet
Author: User
Tags rsync

Shell Project-Distribution system-build file distribution system
    1. Requirement background for large companies, there must be a site or configuration file updates from time to time, and the use of the machine is certainly a lot of units, less than a few, more than dozens of or even hundreds of Taiwan. Therefore, automatic synchronization of files is critical.
    2. The first thing to do is to have a template machine, prepare the files to be distributed, and then simply distribute the files that need to be synchronized to the target machine in batches using the expect script.
    3. Core commandrsync -av --files-from=list.txt / [email protected]:/
Implementation of file distribution system

1.rsync.expect Content

#!/usr/bin/expectset passwd "123456"set host [lindex $argv 0]set file [lindex $argv 1]spawn rsync -av --files-from=$file / [email protected]$host:/expect {"yes/no" { send "yes\r"}"password:" { send "$passwd\r" }}expect eof
    1. Ip.list Content
192.168.133.132192.168.133.133......
    1. rsync.sh Content
#!/bin/bashfor ip in `cat ip.list`do    echo $ip    ./rsync.expect $ip list.txtdone
    1. Exe.expect Content
#!/usr/bin/expectset host [lindex $argv 0]set passwd "123456"set cm [lindex $argv 1]spawn ssh [email protected]$hostexpect {"yes/no" { send "yes\r"}"password:" { send "$passwd\r" }}expect "]*"send "$cm\r"expect "]*"send "exit\r"
    1. exe.sh Content
#!/bin/bashfor ip in `cat ip.list`do    echo $ip    ./exe.expect $ip "w;free -m;ls /tmp"done

Shell Project-Distribution system-build file distribution system

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.