linux shell脚本判断当前登录用户是否为root

脚本实现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

你可能感兴趣的:(linux,shell,linux,shell)