#!/bin/bash
#传递一个参数(用户名)至此函数,如果参数多于一个或少于一个,则退出脚本,并返回错误信息;
# 如果用户名传递正确,显示其UID,并说明其所属的组(包括基本组和附加组),否则,则说明无此用户;
# 如果用户存在,获取用户密码最短和最长使用期限,并显示之;
# 接着判断用户是否登录过系统,如登录过,且当前是否在线,则说明其正在线上;否则,返回其上次登录的时间;如果用户#从未登录系统,则说明其从未登录过。
# 在主脚本中,一直提示用户输入用户名,并判断之,直到用户输入“END”字符退出;
getid(){
echo "The user's uid is `id -u $1`"
echo "The user's `id $1|cut -d' ' -f3`"
echo "The user's password shortest period of use is `grep "^$1" /etc/shadow | cut -d':' -f4`"
echo "The user's password longgest period of use is `grep "^$1" /etc/shadow | cut -d':' -f5`"
finger $1 | grep "On" >>/dev/null && echo "The user of $1 is online."
finger $1 | grep "Last" >>/dev/null && echo "The user of $1 `finger $1 | grep "Last"`."
finger $1 | grep "Never" >>/dev/null && echo "The user of $1 is never login."
}
NAME=0
while [ $NAME != "END" ]
do
read -p "Please input a user name(input "END" for exit):" NAME
#NAME=`dialog --title "Input a user name" --stdout --inputbox "Please input a user name:" 10 30`
if [ `grep "^$NAME" /etc/passwd` ]
then
getid $NAME
elif [ $NAME = "END" ]
then
bash
exit 1 &> /dev/null
else
echo "The user is no exist."
fi
done
阅读(1442) | 评论(0) | 转发(0) |