美文网首页
Shell脚本实现自动输入密码登录服务器

Shell脚本实现自动输入密码登录服务器

作者: 一路清寒 | 来源:发表于2019-04-22 14:34 被阅读0次

    远程拷贝文件例子

    #!/usr/bin/expect

    set timeout 30

    if { [llength $argv] < 2} {

        puts "Usage:"

        puts "$argv0 local_file remote_path"

        exit 1

    }

    #argv 0表示第一个参数

    #[lindex $argv n]获得index为n的参数(index从0开始计算

    set local_file [lindex $argv 0]

    set remote_path [lindex $argv 1]

    set passwd GDJTxxzx123

    set passwderror 0

    spawn scp -r $local_file $remote_path

    expect {

        "*assword:*" {

            if { $passwderror == 1 } {

            puts "passwd is error"

            exit 2

            }

            set timeout 1000

            set passwderror 1

            send "$passwd\r"

            exp_continue

        }

        "*es/no)?*" {

            send "yes\r"

            exp_continue

        }

        timeout {

            puts "connect is timeout"

            exit 3

        }

    }

    相关文章

      网友评论

          本文标题:Shell脚本实现自动输入密码登录服务器

          本文链接:https://www.haomeiwen.com/subject/uqvygqtx.html