缺月挂梧桐 漏断人初静

导航

自动挂载磁盘脚本

 1 #!/bin/bash
 2 set -e
 3 disk(){
 4     disk=`fdisk -l | grep 128 | awk '{print $2}' | tr -d :`  #磁盘名
 5     flag=`df -h | grep $disk `  #查看是否已经挂载  
 6     if [ -n $disk ] ;then
 7         if [ -n $flag ];then
 8              expect -c "   
 9                 spawn  fdisk  $disk
10                    expect {
11                         "Command"    { send \"n\r\"   ; exp_continue }
12                         "Select"     { send \"p\r\"   ; exp_continue }
13                         "Partition"  { send \"1\r\"   ; exp_continue }
14                         "First"      { send \"\r\" ; exp_continue }
15                         "Last"       { send \"\r\" ; exp_continue }          
16                         }   
17                    expect  "Command" { send \"w\r\"}
18                    expect eof
19              "
20              mkdir /data1
21              mkfs.ext4 $disk  -N 5242880
22              mount $disk /data1/
23              sed -i '9a '$disk'     \/data1   ext4    defaults      0  0' /etc/fstab
24         else 
25              echo "$disk already mount~"
26         fi
27     fi
28     
29 }
30 
31 
32 disk

 

 

阿里云扩展系统盘

https://help.aliyun.com/document_detail/111738.html?spm=a2c4g.11186623.2.22.54081035WYrMmt#concept-ocb-htw-dhb

posted on 2019-01-21 17:26  勤劳の洗碗机  阅读(449)  评论(0编辑  收藏  举报