Shell Project-Distribution system-build file distribution system
- 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.
- 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.
- Core command
rsync -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
- Ip.list Content
192.168.133.132192.168.133.133......
- rsync.sh Content
#!/bin/bashfor ip in `cat ip.list`do echo $ip ./rsync.expect $ip list.txtdone
- 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"
- 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