脚本实现1(root-1.sh):
#!/bin/bash
ROOT_UID=0
if [ "$UID" -eq "$ROOT_UID" ];then
echo "You are root."
else
echo "You are just an ordinary user (but mon loves you just the same)."
fi
exit 0
脚本实现2(root-2.sh):
#!/bin/bash
USERS="root"
while :
do
echo "The Time is $(date +%F-%T)"
sleep 10
NUM=$(who | grep $USERS | wc -l)
if [ $NUM -ge 1 ];then
echo "The $USERS is login in system."
fi
done
标签:shell,USERS,just,echo,NUM,linux,root,UID
From: https://blog.51cto.com/ztj1216/7682497