scp.sh
#!/bin/sh
ip_list=/home/tools/scp/iplist
src_file=/home/probecheck.sh
dest_file=/home/
username=root
password=123456
cat $ip_list | while read line
do
host_ip=`echo $line | awk ‘{print $1}‘`
echo "$host_ip"
./scp.exp $host_ip $username $password $src_file $dest_file
done
scp.exp
#!/usr/bin/expect
set timeout 10
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set src_file [lindex $argv 3]
set dest_file [lindex $argv 4]
spawn scp $src_file [email protected]$host:$dest_file
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" {send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect "100%"
expect eof
原文地址:https://www.cnblogs.com/xl-892694298/p/11018841.html
时间: 2024-11-10 12:51:44