zoukankan      html  css  js  c++  java
  • expect 批量执行命令

    在跳板机上执行脚本,登录到远程机器分区格式化挂载命令

    #!/bin/bash
    passwd='engine'
    /usr/bin/expect <<-EOF
    set time 40
    spawn ssh root@172.18.3.114
    expect {
    "*yes/no" { send "yes "; exp_continue }
    "*password:" { send "$passwd " }
    }
    expect "*#"
    send "fdisk /dev/vda "
    expect -exact "Command (m for help):"
    send -- "n "
    expect -exact "Select (default p):"
    send -- "p "
    expect -exact "Partition number (1-4, default 1):"
    send -- "1 "
    expect -exact "First sector"
    send -- "2048 "
    expect -exact "Last sector, +sectors or +size{K,M,G}"
    send -- "1048575999 "
    expect -exact "Command (m for help):"
    send -- "w "
    expect "*#"
    send "echo '/dev/vda1 /home ext4 defaults 0 0' >>/etc/fstab "
    expect "*#"
    send -- "mkfs.ext4 /dev/vda1 "
    expect "*#"
    send -- "mount -a "
    interact
    expect eof
    EOF

  • 相关阅读:
    struts2基础
    hibernate框架基础
    Django的模板层
    HBuilder无法连接夜神模拟器的解决办法
    Django的视图层
    Django的路由层
    Django简介
    http协议
    web应用
    Mongodb之增删改查
  • 原文地址:https://www.cnblogs.com/hixiaowei/p/8297848.html
Copyright © 2011-2022 走看看