本周学习了的内容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