利用shell腳本遠程磁盤分區

在學習linux有關知識,前段時間學習了shell腳本,寫了一個非常簡單的腳本,遠程其他虛擬機進行磁盤分區,自己純手打的,也算是記錄個人學習的一些過程吧,大神可以略過!
下面是腳本內容,可以直接運行的!
系統是CentOS7.4的版本

#!/bin/bash
#利用expect遠程分區
expect << EOF
spawn ssh 172.25.0.11
expect "password" {send "redhat\n"}
expect "#" {send "fdisk /dev/vdb\n"}
expect "命令(輸入 m 獲取幫助)" {send "n\n"}
expect ":" {send "\n"}
expect ":" {send "\n"}
expect ":" {send "\n"}
expect "分區號 (1-4,默認 1):起始 扇區 (2048-20971519,默認爲 2048):" {send\n}
expect "Last 扇區, +扇區 or +size{K,M,G} (2048-20971519,默認爲 20971519):" {send "+500M\n"}
expect "命令(輸入 m 獲取幫助):" {send "w\n"}
expect "#" {send "exit\n"}
EOF

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章