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