Appearance
判断哪些用户登陆了系统
shell
#!/bin/bash
declare -i count=0
while true;do
if who |grep -q -E "^wang"
then
echo -e "用户wang 登陆了系统\\n 这是第$count 次!"
break
else
let count++
fi
sleep 3
done
#示例:找出UID为偶数的所有用户,显示其用户名和ID号; #!/bin/bash
while read line; do
userid=$(echo $line | cut -d: -f3)
if [ $[$userid%2] -eq 0 ]; then
echo $line | cut -d: -f1,3
fi
done < /etc/passwd