shell expect免密码scp拷贝文件到另一台服务器

1.安装expect模块

$ yum install -y expect

2.编写scp免密码登录脚本

$ vim /localshell/expect.sh
#!/usr/bin/expect      
#expect.sh
#各院校应用备份同步一份到30.57,
set timeout 10
set src_file [lindex $argv 0]
spawn scp /home/backup/$src_file [email protected]:/home/backup/
expect "password:"
send "YBGybg123\r"
expect eof

3.运行脚本

$ /usr/bin/expect /localshell/expect.sh

猜你喜欢

转载自blog.csdn.net/Liu_jalon/article/details/88658897
今日推荐