Tuesday 21 April 2015

Write a shell program to check whether given username is valid or not


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

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2022