使用sftp传输文件:读取ip.txt中的ip数据,连接后传输文件
#!/bin/bash
cat ip.txt | while read line
do
echo $line
lftp -u root,password sftp://$line:22 <<EOF
rm -rf aaa.tar
put aaa.tar
bye
EOF
done
使用expect,ssh登录服务器,执行命令:
#!/bin/bash
cat ip.txt | while read line
do
/usr/bin/expect << EOF
set timeout 20
spawn ssh root@$line -l root -p 22
expect "password:" { send "password\r" }
expect "root"
send "tar -xzvf aaa.tar.gz\r"
send "echo role=external > aaa.conf\r"
expect eof
EOF
done