尔会需要在 shell 脚本中通过 scp 传输文件,在此记录下
function auto_scp() {
srcFile=filepath
username='name'
host='1.2.3.4'
dstFile="/var/ftp/filename"
passwd='xxxx'
## 要先过去创建一个目录
expect -c "
set timeout 30
spawn ssh $username@$host \"mkdir -p /var/ftp\n\"
expect {
\"(yes/no)?\" {send \"yes\n\"; expect \"*assword:\" {send \"$passwd\n\"}}
\"*assword:\" {send \"$passwd\n\"}
}
expect eof
"
expect -c "
set timeout 60
spawn scp $srcFile $username@$host:$dstFile
expect {
\"(yes/no)?\" {send \"yes\n\"; expect \"*assword:\" {send \"$passwd\n\"}}
\"*assword:\" {send \"$passwd\n\"}
}
expect eof
"
}
————————————————
版权声明:本文为CSDN博主「tanyijanuary」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/tanyijanuary/article/details/53467064