Wednesday 9 September 2015

adding user and access permission

#################################################
# assignment no: 3
# title :adding user and access permission
# date:4-8-2015
# iName: Kishor Sonawane
#################################################
cnt=1
while [ $cnt -eq 1 ]
do


echo "------------------------------------------"
echo "1.Add user"
echo "2.Add group:"
echo "3.Add existing user in group:"
echo "4.Set access rights:"
echo "5.Change group of file:"
echo "6.Change owner of file"
echo "7. Switch user"
echo "8. Remove  user"
echo "9. Remove group "
echo "-------------------------------------------"
echo "enter your choice::"
read ch

case $ch in

1) #Add user

echo "Enter the user name to add::"
read uname1
sudo adduser $uname1
echo "all user info ::"
sudo cat /etc/group
;;

2) #Add group

echo "Enter the group name to add::"
read gname1
sudo addgroup $gname1
;;

3) # Add existing user in group

echo "Enter the Existing  user name to add in group::"
read uname1
echo "enter the group name to add user"
read gname1
sudo adduser $uname1 $gname1
;;


4)
#Set access rights
echo "enter the file name::"
read fname
echo "current information of $fname :: "
getfacl $fname
echo "Enter the new access permission in numbers (owner - group - all other)::"
read accper
sudo chmod $accper $fname
echo "Updated information of $fname ::"
getfacl $fname
;;
5)
#Change owner of file
echo "enter the file name::"
read fname
echo "current information of $fname :: "
getfacl $fname
echo "ente new group owner name :"
read  gown 
sudo chgrp $gown $fname
echo "Updated information of $fname ::"
getfacl $fname
;;
6)
#Change owner of file
echo "enter the file name::"
read fname
echo "current information of $fname :: "
getfacl $fname
echo "Enter the new ownwr name:"
read own
sudo chown $own $fname
echo "Updated information of $fname ::"
getfacl $fname
;;

7) #Switch user
echo "current user ::"
whoami
echo "enter user name to switch ::"
read user
su $user
echo "After switching ::current user "
whoami
;;
8) #Remove  user
echo "Enter user name to remove::"
read uname1
sudo deluser $uname1
echo "All user info::"
sudo cat /etc/psswd
;;
9)
# Remove group
echo "enter group name to remove :"
read gname1
sudo delgroup $gname
echo "All user info::"
sudo cat /etc/group
;;
*) #default case
    echo "invalid choice !!!"
   ;;
esac
echo "to continue press 1:"
read cnt
done




No comments:

Post a Comment