#!/bin/bash
# chk_root.sh
#
echo test my computer is or not safety #显示“ test my computer is or not safety ”
root_num=`
awk -F: '{print $3}' /etc/passwd|grep "^0"|wc -l` #以“:”为分隔符,打印出/etc/passwd文件中第三个域的字段,并grep以“0”开头的(意思是UID是0的用户),然后计算
行数(3行代表有3个UID为0的用户,包括root),最终赋值给root_num.
if [ $root_num -eq 1 ];then #如果$root_num的值为1,表示只有一个root用户
echo your computer is safety #显示“ your computer is safety ”
else #否则
awk -F: '{print $3,$1}' /etc/passwd|grep "^0"|grep -v "root" >> hack1 #打印/etc/passwd中的第三个域(UID)和第一个域(用户名),并且grep以“0”开头的行,输出到hack1的文
件中
cat hack1|awk '{print $2}'>>hack #查看hack1文件的内容,并打印出第二个域的内容,输出到hack文件中
for number in `cat hack` #查看hack的内容,并循环赋值给number
do
echo $number mybe created by hacker. #显示“ xxx mybe created by hacker.”
read -p "are you want to delete it? y or n :" answer #显示“are you want to delete it? y or n :“
if [ $answer = "y" ] #如果回答是”y“
then
userdel -r $numeber #删除xxx
echo $number is delete. #显示”xxx is dele“
if [ $answer = "yes"] #如果回答是”yes“
then
userdel -r $number
echo $number is delete.
fi
fi
done
fi
rm -f hack* #删除hack和hack1文件