首页 > 学院 > 操作系统 > 正文

监视/etc/passwd文件是否正常

2024-06-28 13:24:58
字体:
来源:转载
供稿:网友
监视/etc/passwd文件是否正常

帮助监视/etc/passwd文件是否正常(P90 练习6.7)

1)找出有UID0的所有项

2)找出有重复UID的所有项

3)找出有重复登录名的所有项

4)找出没有口令的所有项

5)找出没有作废日期的所有项

以下是实现的shell脚本:

#!/bin/bash#监视/etc/passwd正常

#找出有UID 0的用户echo "----------------------------------"user1=`less /etc/passwd | awk -F: '$3==0 {PRint $1}'`if [ -z $user1 ];then echo "1.there is no user's UID equals 0"elseecho -n "1.the user of UID equals 0 have: "$user1echo ""fi

#找出有重复UID的用户echo "----------------------------------"user2=`awk -F: 'BEGIN{ORS=","}NR==FNR {a[$3]++} NR>FNR&&a[$3]>1 {print $1,$3}' /etc/passwd /etc/passwd`if [ -z $user2 ];then echo "2.there is no user's UID repeat"elseecho -n "2.the user of repeat UID have: "$user2echo ""fi

#找出有重复登录名的用户echo "---------------------------------"user3=`awk -F: 'BEGIN{ORS=","}NR==FNR {a[$1]++} NR>FNR&&a[$1]>1 {print $1,$3}' /etc/passwd /etc/passwd`if [ -z $user3 ];then echo "3.there is no user's login name repeat"elseecho -n "3.the user of repeat login name have: "$user3echo ""fi

#找出没有口令的所有用户echo "---------------------------------"user4=`sudo awk -F: 'BEGIN{ORS=","} length($2)<30 {print $1}' /etc/shadow`if [ -z $user4 ];then echo "4.there is no user have no passWord"elseecho -n "4.the user of no password have: "$user4echo ""fi

#找出没有作废日期的所有用户echo "---------------------------------"user5=`sudo awk -F: 'BEGIN{ORS=","} length($7)<1 {print $1}' /etc/shadow`if [ -z $user5 ];then echo "5.there is no user have no outdate time"elseecho -n "5.the user of no outdate time have: "$user5echo ""fiecho "---------------------------------"


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表