linux下脚本式使用scp命令,并且避免第一次与一台主机交互时
2019-01-08 本文已影响0人
努力编程的小蚂蚁
linux下脚本式使用scp命令,并且避免第一次与一台主机交互时的确认交互步骤卡死脚本的执行
此脚本的执行需要linux系统已安装了 expect
可以使用 which expect 命令查看是否已经安装此插件
安装命令为 yum -y install expect
#!/usr/bin/expect -f
# Script From Chenkl. Use SCP Push A File To The Target Host. Need Install expect.
# First Param Is Target Host Username@IP.
# Second Param Is Target Host Directory.
# Third Param Is Local Host File.
# Fourth Param Is Target Host Password.
set timeout 30
spawn scp [lindex $argv 2] [lindex $argv 0]:[lindex $argv 1]
expect {
"passphrase"
{
send "[lindex $argv 3]\n";
}
"password"
{
send "[lindex $argv 3]\n";
}
"yes/no"
{
send "yes\n";
exp_continue;
}
}
expect eof