OSA A3

Q 3A: To study adding of users and also access rights.
->   Program:

while true

do

echo "1.Create group:";
echo "2.Create users:";
echo "3.Delete users:";
echo "4.Delete group"
echo "5.Display users and groups in the system"
echo "6.Exit";

echo "Enter your choice : ";

read ch;
case $ch in
1)

echo "Enter the group name  :"
read gname
groupadd $gname
system-config-users
;;                                              # to break first switch case

2)
echo "Enter the user name :";
read username

echo "Enter the group name :";
read gname

useradd $username -g $gname

system-config-users
;;

3)
echo "delete the user"
echo "enter the name of the user "
read username
userdel $username
system-config-users
;;

4)
echo "delete group"
echo "enter name of  a group "
read gname
groupdel $gname
system-config-users
;;

5)
echo "Dispaly users and groups from the system:"
system-config-users
;;

6)
exit;
;;
esac                                         # end of switch case
done




OUTPUT:-
[student@localhost ~]$ cd Documents/Assignments
[student@localhost Assignments]$ ls
A-1f.sh   A-2.sh   A-4.sh    Assign14B.zip     CpuInfo.java  file_name2
A-1f.sh~  A-2.sh~  A-5.sh    Assign2final.zip  debug.py      test1
A-1.sh    A-3.sh   A-6.sh    Assign6B.zip      debug.py~
A-1.sh~   A-3.sh~  Assign14  CpuInfo.class     file_name1
[student@localhost Assignments]$ ./A-3.sh
1.Create group:
2.Create users:
3.Delete users:
4.Delete group
5.Display users and groups in the system
6.Exit
Enter your choice :
1
Enter the group name  :
abc
./A-3.sh: line 20: /usr/sbin/groupadd: Permission denied
Error executing command as another user: Request dismissed
/*Group and user addition are functions which can only be carried on by the root user! Hence a normal user cannot create or delete users or groups. So we switch to the root user using the 'su' command! */
1.Create group:
2.Create users:
3.Delete users:
4.Delete group
5.Display users and groups in the system
6.Exit
Enter your choice :
6
[student@localhost Assignments]$ su
Password:
[root@localhost Assignments]# ./A-3.sh
1.Create group:
2.Create users:
3.Delete users:
4.Delete group
5.Display users and groups in the system
6.Exit
Enter your choice :
1



Enter the group name  :
clubs




































[root@localhost Assignments]# ./A-3.sh
.Create group:
2.Create users:
3.Delete users:
4.Delete group
5.Display users and groups in the system
6.Exit
Enter your choice :
2
Enter the user name :
barcelona
Enter the group name :
clubs
1.Create group:
2.Create users:
3.Delete users:
4.Delete group
5.Display users and groups in the system
6.Exit
Enter your choice :
2
Enter the user name :
manchesterunited                               
Enter the group name :
clubs
1.Create group:
2.Create users:
3.Delete users:
4.Delete group
5.Display users and groups in the system
6.Exit
Enter your choice :
2
Enter the user name :
realmadrid
Enter the group name :
clubs








[root@localhost Assignments]# ./A-3.sh
1.Create group:
2.Create users:
3.Delete users:
4.Delete group
5.Display users and groups in the system
6.Exit
Enter your choice :
3
delete the user
enter the name of the user
test
userdel: user 'test' does not exist
1.Create group:
2.Create users:
3.Delete users:
4.Delete group
5.Display users and groups in the system
6.Exit
Enter your choice :
3
delete the user
enter the name of the user
manchesterunited




[root@localhost Assignments]# ./A-3.sh
1.Create group:
2.Create users:
3.Delete users:
4.Delete group
5.Display users and groups in the system
6.Exit
Enter your choice :
4
delete group
enter name of  a group
clubs
groupdel: cannot remove the primary group of user 'barcelona'

/*Clubs is the primary group of  Barcelona. We cannot delete a primary group of  any user!
Therefore, we couldn't delete group 'clubs' */



[root@localhost Assignments]# ./A-3.sh
1.Create group:
2.Create users:
3.Delete users:
4.Delete group
5.Display users and groups in the system
6.Exit
Enter your choice :
1
Enter the group name  :
clubs2

/* Here we created a new group and added Barcelona to it! Now let's try deleting clubs 2! */



1.Create group:
2.Create users:
3.Delete users:
4.Delete group
5.Display users and groups in the system
6.Exit
Enter your choice :
4
delete group
enter name of  a group
clubs2
/* Yes! We could succesfully delete 'clubs2' as it is not a primary group of any user. */



[root@localhost Assignments]# ./A-3.sh
1.Create group:
2.Create users:
3.Delete users:
4.Delete group
5.Display users and groups in the system
6.Exit
Enter your choice :
5
Dispaly users and groups from the system:


0 comments:

Post a Comment