本周学习大概总结

本周学习了的内容yum源的配置,find工具的查找,文件的压缩,sed文本处理工具,脚本编辑的基础,磁盘的管理与存储以及网络yum源服务器的配置。

附上自己编写的脚本
上允许普通用户登录,下禁止普通用户登录

test -a /etc/nologin && rm -rf /etc/nologin || { echo "the user is unlocked" ; exit 1 ; }
echo "the user is unlocked sucess"

! test -a /etc/nologin && touch /etc/nologin || { echo "the user is locked " ; exit 1 ; }
echo "the user is locked sucess"

当磁盘和节点编号超过80%报警

warn=80          
diskuser=`df|grep "^/dev/sd.*"|grep -Eo "[[:digit:]]{1,3}%" |tr -d "%" |sort -rn|head -n1`
inodeuser=`df -i|grep "^/dev/sd.*"|grep -Eo "[[:digit:]]{1,3}%" |tr -d "%" |sort -rn|head -n1`
[ $diskuser -gt $warn ] && wall "you need cleal disk" || echo "you not need cleal disk"
[ $inodeuser -gt $warn ] && wall "you need cleal diskinode" || echo "you not need cleal diskinode"
unset warn diskuser inodeuser

检测空白行

 $# -lt 1 ] && { echo "at least one argument" ; exit 1 ; }
 [[ $1 =~ ^/.* ]] || { echo "plese give ture path or absolute path " ; exit 1 ; }
 [ -a $1 ] && echo `cat $1 |grep ^[[:space:]]$|wc -l` || echo "plese give ture base"

检测输入数字是不是正数

if [ -z $1 ] ; then
         read -p "plese input a number:" number               if [ -z $number ] ; then
                  { echo "you input number is null" ; exit 1 ; }
                  fi
else
       number=$1
fi
if [[ $number =~ ^[0-9]+$ ]] ; then         echo        "     the $number is int"
else
         echo "the $number not int"
fi

自动创建用户并显示ID

[ -z $1 ] && read -p"plese input a username:" name || name=$1
if id $name &> /dev/null ; then
           echo " the username exists "
else
            useradd $name ; id $name
fi

检测文件属性

if [ -z $1 ] ; then
         { echo " plase input file path" ; exit 1 ; }
 elif [ -f $1 ] ; then
           echo "this is nomal file"
 elif [ -d $1 ] ; then
           echo "this is dir file"
 elif [ -l $1 ] ; then
           echo "this is link file"
 else
           echo "this is other file"
 fi

检测你输入的是YES或NO

if [ $# -eq 0 ] ; then
           read -p "plase input yes or no:" input
                  if [ -z $input ] ; then
                      { echo "Since the content you entered is empty, please restart it" ; exit 1 ;  }
                  fi
else
              input=$1
fi
if [[ $input =~ ^[Yy]([Ee][Ss])?$ ]] ; then
           echo "you input is yes"
elif [[ $input =~ ^[Nn][Oo]?$ ]] ; then
            echo "you input is no"
else
           echo "plase input a ture yes or no"
fi

转载于:https://blog.51cto.com/14234933/2368962

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值