expect 批量執行命令


在跳板機上執行腳本,登錄到遠程機器分區格式化掛載命令

#!/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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM