在shell脚本中实现 scp 文件的时候不手动输入密码

原创
2017/08/10 14:32
阅读数 4.7K

参数说明:
-r:拷贝目录
-c:允许压缩

执行脚本:

#!/usr/bin/expect -f
set password 密码
#download
spawn scp root@ip:/root/a.wmv /home/yangyz/
set timeout 300 
expect "root@ip's password:"
set timeout 300 
send "$password\r"
set timeout 300 
send "exit\r"
expect eof

#upload
spawn scp /home/xxx.sql root@ip:/root/xxx.sql 
set timeout 300 
expect "root@ip's password:"
set timeout 300 
send "$password\r"
set timeout 300 
send "exit\r"
expect eof

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部