1. Single Transmission script
The code is as follows |
Copy Code |
cat/root/soft_shell/allscp.sh #!/usr/bin/expect If {$ARGC < 2} { Send_user "Usage: $ARGV 0 src_file username IP dest_file Passwordn" Exit } # #set Key [lindex $argv 0] Set src_file [lindex $argv 0] Set username [lindex $argv 1] Set HOST_IP [lindex $argv 2] Set dest_file [lindex $argv 3] Set password [lindex $argv 4] # #spawn scp-i $key $src _file $username @ $host _ip: $dest _file Spawn SCP $src _file $username @ $host _ip: $dest _file Expect { "(yes/no)?" { Send "YESN" Expect "Password:" {send "$passwordn"} } "Password:" { Send "$passwordn" } } Expect "100%" Expect EOF |
2. Multiple Transmission scripts
code is as follows |
copy code |
cat/root/soft _shell/mainscp.sh #!/bin/bash host_list= "server_list.conf" Cat $host _list | While read line do host_ip= ' echo $line |awk ' {print $} ' username= ' echo $line |awk ' {print $} ' password= ' echo $ Line|awk ' {print $} ' src_file= ' echo $line |awk ' {print $} ' dest_file= ' echo $line |awk ' {print $} ' ' # #key = ' echo $line |awk ' {print $} ' ##./allscp.sh $key $src _file $username $host _ip $dest _file $pa ssWOrd /allscp.sh $src _file $username $host _ip $dest _file $password Done |
3. Server information file
The code is as follows |
Copy Code |
Cat/root/soft_shell/server_list.conf
|
The format is:
IP Username password source file destination file address
PS: Above 3 files, I believe everyone can see that they are placed under the same folder. My local test only use SSH password, without SSH key, if you want to use the same as our company's formal environment security (SSH password +key to log on to the server), then please modify your script file, I'm lazy and I don't have to talk about it so much.
Finally, a picture of the effect, lest people say I have a script problem.