帮助监视/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"
else
echo -n "1.the user of UID equals 0 have: "$user1
echo ""
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"
else
echo -n "2.the user of repeat UID have: "$user2
echo ""
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"
else
echo -n "3.the user of repeat login name have: "$user3
echo ""
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"
else
echo -n "4.the user of no password have: "$user4
echo ""
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"
else
echo -n "5.the user of no outdate time have: "$user5
echo ""
fi
echo "---------------------------------"

最新文章

  1. linux中输入输出和重定向问题
  2. 【腾讯云的1001种玩法】在腾讯云上创建您的SQL Cluster(5)
  3. AngularJs angular.Module模块接口配置
  4. 11号了,还有三天上线-改bug
  5. Java 语句总结
  6. EasyUI实例源码
  7. createjs基础
  8. Django初学笔记1.
  9. 【男性身材计算】胸围=身高*0.48(如:身高175cm的标准胸围=175cm*0.61=84cm);腰围=身高*0.47(如:身高175c… - 李峥 - 价值中国网
  10. 最简单的视频编码器:基于libx265(编码YUV为H.265)
  11. Swift实现JSON转Model - HandyJSON使用讲解
  12. 【框架学习与探究之宿主服务--Topshelf】
  13. 从零开始学习前端JAVASCRIPT — 2、JavaScript基础ES5
  14. WPF自定义控件创建
  15. 野路子码农系列(3)plotly可视化的简单套路
  16. SQL SERVER 小语法
  17. day8--socketserver回顾
  18. 【图像基础】图像不变性特征HU矩和Zernike矩
  19. win10开移动热点让手机使用上网
  20. linux shell 脚本攻略学习2

热门文章

  1. hbulider 快捷键以及常用
  2. 第一个小项目(天气预报软件)——称&quot;酷狗天气&quot;
  3. freemaker的基本语法
  4. Java SE Eclipse中引入第三方jar及class
  5. java基础入门-arraylist存储开销
  6. 使用java进行文件编码转换
  7. Tomcat配置gzip压缩
  8. careercup-数组和字符串1.8
  9. 为centos6.5系统添加epel源
  10. Google Map API v2 步步为营 (二)----- Location