shell简单脚本#1

判断/etc/inittab文件是否大于100行,如果大于,则显示”/etc/inittab is a big file.”否者显示”/etc/inittab is a small file.”

#!/bin/bash
Line =`wc -l /etc/inittab | cut -d' ' -f1`
if[$Line -gt 100];then
echo"it's a big file"
else
echo"it's a small file"
fi

给定一个用户,来判断这个用户是什么用户,如果是管理员用户,则显示“该用户为管理员”,否则显示“该用户为普通用户”

#!/bin/bash          
USERID
=`id -u $1`
if [ $USERID -eq 0 ]; then echo "Admin" else echo "Common user." fi

判断某个文件是否存在

           #!/bin/bash
                  #if [ -e $1 ]; then
                     echo "File exists."
                  else
                     echo "File does not exists."
                  fi

判断当前系统上是否有用户的默认shell程序是否为bash程序,如果有,就显示有多个这类用户,否则就显示没有这类用户;【并且显示出那些用户是bash】

#!/bin/bash
BASHLINE=`grep "bash$" /etc/passwd | wc -l`
     if [ $BASHLINE -eq 0 ]; then
       echo "We don‘t have /bin/bash user."
     else
       echo "We have $BASHLINE user,This number is $BASHLINE."
       echo "grep bash$ /etc/passwd | cut -d‘:‘ -f1" 
     fi
原文地址:https://www.cnblogs.com/schoolboy999/p/11338522.html