#!/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}#检测输入参数是否为2if [ $# -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 1fi#确认是否格式化磁盘read -p "Are you sure you want to format $1 (y|n). " ancase $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 1fi
©著作权归作者所有:来自51CTO博客作者Margotchen的原创作品,谢绝转载,否则将追究法律责任

更多相关文章

  1. 微信小程序实现带参分享并消息卡片获取参数
  2. JavaScript初学习之常量、变量、函数、匿名函数、箭头函数、闭包
  3. JavaScript 中 call()、apply()、bind() 的用法
  4. 【Nest教程】实现一个简单的用户增删改查功能
  5. C#中方法的调用
  6. C++入门
  7. 如何检测社交网络中两个人是否是朋友关系(union-find算法)
  8. ubuntu系统如何配置***检测系统AIDE?
  9. 剩余参数与参数引用及回调函数:array_map(), array_filter,array_

随机推荐

  1. golang数组与切片的区别是什么?
  2. golang语言可以做些什么
  3. golang如何判断数据类型
  4. golang是什么语言?
  5. golang语言的出现解决了什么问题
  6. golang如何创建map
  7. golang有什么用途?
  8. golang怎么截获错误
  9. golang如何导入包
  10. golang Web框架有哪些?