zoukankan      html  css  js  c++  java
  • expect 自动输入密码

    测试环境centos 6.5 7.4

    1、远程登陆执行命令  scp

    #!/bin/bash

    expect -c '
    set timeout 10000
    spawn ssh root@192.168.67.22

    #spawn scp ./3.sh 192.168.67.133:/root/zzx/

    expect {
    "yes/no" {send "yes "; exp_continue}
    "*assword" {send "1 "}
    }
    expect "#"
    #send "ip a " #send "sleep 1 "
    send "hostname "
    expect "#"
    send "echo 123 "
    expect "#"
    send "exit "
    #interact #注释上面两行(exit去掉) 这一行注释去掉可以停在远程机器    interact 
    '
    #以下和expect无关
    #hostname
    echo "end expect"

     2、scp

    #!/bin/bash
    src=/root/zzx
    dsc=/root/zzx
    expect -c "
    spawn scp -r $src/scp.sh root@192.168.67.133:$dsc
    expect {
    "*assword" {set timeout 300; send "1
    ";}
    "yes/no" {send "yes
    "; exp_continue;}
    }
    expect eof" 
  • 相关阅读:
    Spring MVC(一)
    Spring-IOC总结
    IT
    Spring基础
    Maven
    Ajax笔记
    数据库和SQL语言
    JDBC
    拦截器
    文件上传
  • 原文地址:https://www.cnblogs.com/hanxing/p/7831751.html
Copyright © 2011-2022 走看看