首页 > 其他 > 详细

95.自动挂载云盘

时间:2021-02-28 10:51:49      阅读:15      评论:0      收藏:0      [点我收藏+]
#!/bin/bash #The script is used to mount cloud disk automatically. #Date 2021-02-27 #检测命令是否执行成功 check_command() { if [ $? -ne 0 ];then echo "$1 command is error,please check again." exit 1 fi } #检测输入参数是否为2 if [ $# -ne 2 ];then echo "Please input two parameters." exit 1 #检测第一个参数是否为设备文件 elif ! [ -b $1 ];then echo "Please check the first parameter $1 is a disk dir again." exit 1 #检测第二个参数是否为以根目录/开头文件 elif ! echo "$2" |grep -q ‘^/‘;then echo "Please input the correct format,like: /dir " exit 1 fi #确认是否格式化磁盘 read -p "Are you sure you want to format $1 (y|n). " an case $an in y|Y) echo "formatting $1" mkfs -t ext4 $1 ;; n|N) echo "Bye." exit 1 ;; *) echo "Please input y or n." ;; esac #挂载目录不存在则创建挂载目录 [ -d $2 ] || mkdir -p $2 #检测/etc/fstab配置文件是否已经存在该挂载点 n=`grep "$2" /etc/fstab |wc -l` #不存在则配置挂载点 if [ "$n" -eq 0 ];then echo "$1 $2 ext4 defaults 0 0" >> /etc/fstab mount -a check_command `echo ‘mount‘` else echo "The mount point $2 already exists in /etc/fstab configuraton file. " exit 1 fi

95.自动挂载云盘

原文:https://blog.51cto.com/11594671/2641149

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!