This shell program checks and returns the appropriate message about the logged in users in system also checks whether user name is valid or not.
list_users=`cat /etc/passwd | cut -d ":" -f 1 | grep $1` list_logged_users=`who | cut -d " " -f 1 | head -1` echo "**********************************" if [ "$list_users" == "$1" ]; then # if valid user if [ "$list_logged_users" == "$1" ]; then echo "The given user is logged in" exit 1 else echo "The user not logged in" fi else echo "Not a valid user" fi
No comments:
Write comments