linux下脚本式使用scp命令,并且避免第一次与一台主机交互时的确认交互步骤卡死脚本的执行

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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、Python简介和环境搭建以及pip的安装 4课时实验课主要内容 【Python简介】: Python 是一个...
    _小老虎_阅读 5,848评论 0 10
  • feisky云计算、虚拟化与Linux技术笔记posts - 1014, comments - 298, trac...
    不排版阅读 3,939评论 0 5
  • 1.描述计算机的组成及其功能 (一)计算机的组成 1.CPU 2.CPU风扇 3.BIOS 4.内存 5.硬盘 6...
    whamai阅读 1,514评论 0 1
  • Linux习惯问题: 在vim编辑时,按了ctrl + s后,再按ctrl + q就可以继续执行了。ctrl + ...
    光着脚的鞋阅读 4,550评论 0 16
  • 官网 中文版本 好的网站 Content-type: text/htmlBASH Section: User ...
    不排版阅读 4,499评论 0 5