zoukankan      html  css  js  c++  java
  • 分发系统介绍 expect脚本远程登录 expect脚本远程执行命令 expect脚本传递参数

    expect脚本远程登录

      yum install -y expect
      yum install -y tcl tclx tcl-devel
    

      自动远程登录

     #! /usr/bin/expect
    set host "192.168.133.132"
    set passwd "123456"
    spawn ssh root@$host
    expect {
    "yes/no" { send "yes
    "; exp_continue}
    "password:" { send "$passwd
    " }
    }
    interact

    自动远程登录后,执行命令并退出

    #!/usr/bin/expect
    set user "root"
    set passwd "123456"
    spawn ssh $user@192.168.133.132
    expect {
    "yes/no" { send "yes
    "; exp_continue}
    "password:" { send "$passwd
    " }
    }
    expect "]*"
    send "touch /tmp/12.txt
    "
    expect "]*"
    send "echo 1212 > /tmp/12.txt
    "
    expect "]*"
    send "exit
    "

      传递参数

      传递参数
    #!/usr/bin/expect
    set user [lindex $argv 0]
    set host [lindex $argv 1]
    set passwd "123456"
    set cm [lindex $argv 2]
    spawn ssh $user@$host
    expect {
    "yes/no" { send "yes
    "}
    "password:" { send "$passwd
    " }
    }
    expect "]*"
    send "$cm
    "
    expect "]*"
    send "exit
    "
    
    chmod +x ex3.sh
    [root@localhost sbin]# ./ex3.sh  root 192.168.1.3 ls
  • 相关阅读:
    spring cloud stream定时器 配置rabbitmq插件安装
    字母、单词统计
    动手动脑
    原码补码反码
    ATM
    开学第一课
    周进度报告8
    周进度报告7
    JavaWeb进度报告1
    周进度报告6
  • 原文地址:https://www.cnblogs.com/zhaocundang/p/8972292.html
Copyright © 2011-2022 走看看