码迷,mamicode.com
首页 > 其他好文 > 详细

expect 批量执行命令

时间:2018-01-17 00:41:59      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:word   command   home   size   inter   ext   engine   分区格式化   pass   

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

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

expect 批量执行命令

标签:word   command   home   size   inter   ext   engine   分区格式化   pass   

原文地址:https://www.cnblogs.com/hixiaowei/p/8297848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!