完善了一下公司自动初始服务器的脚本,添加了自动挂载磁盘的脚本,写的比较烂,但是还是记录一下,以供以后参考,在初始化服务器脚本里面调用了mountdisk.sh脚本,mountdisk.sh里面又调用了format.sh脚本,脚本内容如下:
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:
#!/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目录下。各位可以根据需求自行修改。