需要安装expect环境
yum install expect -y vi ip.txt #主机地址池 192.168.1.1 192.168.1.2 192.168.3.3 #如果是同一网段也可以不用地址池文件直接写 for ip in $(seq 1 255) # ${ip}换成192.168.10.$ip vi scp.sh #创建scp.sh文件 #!/bin/bash #code junwei.xin password=”password” for ip in $(cat ip.txt) do /usr/bin/expect <<-EOF spawn scp -oStrictHostKeyChecking=no /opt/NO2/test.file root@${ip}:/tmp expect “password:” send “$password\r” set timeout 300 expect eof EOF done chmod +x #添加执行权限 ./scp.sh #运行脚本