Today, the company colleagues in a server on the other two servers with the computer room for file transfer, the two server files to store the same address, the password and key is consistent (our company in security to do a bit of a pervert), in order to efficiency wrote the following script.
1. Single Transmission script
cat/root/soft_shell/allscp.sh
Copy Code code as follows:
#!/usr/bin/expect
If {$ARGC < 2} {
Send_user "Usage: $ARGV 0 src_file username IP dest_file password\n"
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 "yes\n"
Expect "Password:" {send "$password \ n"}
}
"Password:"
{
Send "$password \ n"
}
}
Expect "100%"
Expect EOF
2. Multiple Transmission scripts
cat/root/soft_shell/mainscp.sh
Copy Code code as follows:
#!/bin/bash
Host_list= "Server_list.conf"
Cat $host _list | While Read line
Todo
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 $password
/allscp.sh $src _file $username $host _ip $dest _file $password
Done
3. Server information file
Copy Code code as follows:
Cat/root/soft_shell/server_list.conf
The format is:
Copy Code code as follows:
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.