zoukankan      html  css  js  c++  java
  • expect 交互 之shell执行命令操作

    shell 执行命令操作

    /usr/bin/expect -c "
    proc jiaohu {} {
        send_user expect_start
        expect {
            password {
                send ${RemotePasswd}
    ;
                send_user expect_eof
                expect {
                    "does not exist" {
    send_user expect_failure
    exit 10
                    }
                    password {
    send_user expect_failure
    exit 5
                    }
                    Password {
    send ${RemoteRootPasswd}
    ;
    send_user expect_eof
    expect {
        incorrect {
            send_user expect_failure
            exit 6
        }
        eof 
    }
                    }
                    eof
                }
            }
            passphrase {
                send ${KeyPasswd}
    ;
                send_user expect_eof
                expect {
                    "does not exist" {
    send_user expect_failure
    exit 10
                    }
                    passphrase{
    send_user expect_failure
    exit 7
                    }
                    Password {
    send ${RemoteRootPasswd}
    ;
    send_user expect_eof
    expect {
        incorrect {
            send_user expect_failure
            exit 6
        }
        eof
    }
                    }
                    eof
                }
            }
            Password {
                send ${RemoteRootPasswd}
    ;
                send_user expect_eof
                expect {
                    incorrect {
    send_user expect_failure
    exit 6
                    }
                    eof
                }
            }
            "No route to host" {
                send_user expect_failure
                exit 4
            }
            "Invalid argument" {
                send_user expect_failure
                exit 8
            }
            "Connection refused" {
                send_user expect_failure
                exit 9
            }
            "does not exist" {
                send_user expect_failure
                exit 10
            }
            
            "Connection timed out" {
                send_user expect_failure
                exit 11
            }
            timeout {
                send_user expect_failure
                exit 3
            }
            eof
        }
    }
    set timeout $TimeOut
    switch $1 {
        Ssh_Cmd {
            spawn ssh -t -p $Port -o StrictHostKeyChecking=no $RemoteUser@$Ip /bin/su - root -c \"$Cmd\"
            jiaohu
        }
        Ssh_Script {
            spawn scp -P $Port -o StrictHostKeyChecking=no $ScriptPath $RemoteUser@$Ip:/tmp/${ScriptPath##*/};
            jiaohu
            spawn ssh -t -p $Port -o StrictHostKeyChecking=no $RemoteUser@$Ip /bin/su - root -c  \"/bin/sh /tmp/${ScriptPath##*/}\" ;
            jiaohu
        }
        Scp_File {
            spawn scp -P $Port -o StrictHostKeyChecking=no -r $ScpPath $RemoteUser@$Ip:${ScpRemotePath};
            jiaohu
        }
    }
    "
    state=`echo $?`
  • 相关阅读:
    【Android】: 部分注意事项
    【Java】:多线程下载
    【操作系统】:Main features of the X86-64
    「数据结构」:模拟指针(simulated pointer)
    「JAVA」:Berkeley DB的JAVA连接
    「python」: arp脚本的两种方法
    「数据结构」: 间接寻址
    「操作系统」: Conditional Move Instructions(trap)
    「操作系统」:The most useful condition codes
    quartz定时任务时间设置
  • 原文地址:https://www.cnblogs.com/sharesdk/p/8710066.html
Copyright © 2011-2022 走看看