Shell (build file distribution System)

Source: Internet
Author: User
Tags rsync

1. Requirements 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 sets. Therefore, automatic synchronization of files is critical.

2. Realization of Ideas
Start with a template machine, prepare the files to be distributed, and then distribute the files that need to be synchronized to the target machine in batches using the expect script.
3. Core commands
Rsync-av--files-from=list.txt/[Email protected]:/
4. Implementation of the document distribution system
Vim Rsync.expect

#!/usr/bin/expect
Set 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

(Vim ip.list vim file.list Create IP and file list)

Vim rsync.sh

#!/bin/bash
For IP in ' cat ip.list '
Do
Echo $ip
./rsync.expect $ip List.txt
Done

5. command batch execution script
Vim Exe.expect

#!/usr/bin/expect
Set host [lindex $ARGV 0]
Set passwd "123456"
Set cm [lindex $argv 1]

Spawn ssh [email protected] $host

Expect {
"Yes/no" {send "yes\r"}
"Password:" {send "$passwd \ r"}
}
Expect "]*"
Send "$cm \ r"
Expect "]*"
Send "exit\r"

Vim exe.sh

#!/bin/bash
For IP in ' cat ip.list '
Do
Echo $ip
./exe.expect $ip "W;free-m;ls/tmp"
Done

Shell (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.