linux下腳本式使用scp命令雇锡,并且避免第一次與一臺主機交互時的確認交互步驟卡死腳本的執(zhí)行
此腳本的執(zhí)行需要linux系統(tǒng)已安裝了 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