自動掛載磁盤腳本

完善了一下公司自動初始服務器的腳本,添加了自動掛載磁盤的腳本,寫的比較爛,可是仍是記錄一下,以供之後參考,在初始化服務器腳本里面調用了mountdisk.sh腳本,mountdisk.sh裏面又調用了format.sh腳本,腳本內容以下:bash

mountdisk.sh:
服務器

#!/bin/bash
disk=/dev/sdb1
if [ `df -h|grep $disk|wc -l` == 1 ];then
echo "disk $disk is mount"
exit
fi
if [ ! -f /usr/bin/expect ];then
yum -y install expect expect-devel
fi
/usr/bin/expect -f ./format.sh
mkfs.ext4 $disk
if [ ! -d /data ];then
mkdir /data
fi
if [ ! `grep "$disk" /etc/fstab|wc -l` == 1 ];then
echo "$disk              /data                   ext4    defaults,acl    0 0">> /etc/fstab
fi
mount -a

format.sh:
ide

#!/usr/bin/expect
set timeout 30
spawn fdisk /dev/sdb
expect "(m for help):"
send "d\r"
expect "(m for help):"
send "n\r"
expect "(default p):"
send "p\r"
expect "default 1):"
send "\r"
expect "):"
send "\r"
expect "):"
send "\r"
expect "(m for help):"
send "w\r"
expect eof

做用是會自動查找到系統中的/sdb磁盤,進行格式化,而後掛載到/data目錄下。各位能夠根據需求自行修改。spa

相關文章
相關標籤/搜索