-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_create_mod.sh
66 lines (58 loc) · 1.89 KB
/
user_create_mod.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
echo "press 1 to create a new user"
echo "press 2 to change password of an existing user"
echo "press 3 to delete a user"
read -p "Please enter number from above choice:" Entry
if [ $Entry -eq 1 ]; then
read -p "please enter the user name: " user
if [ -z "$user" ]; then
echo "username can't be empty"
exit 1
else
cat /etc/passwd | grep -i $user
if [ $? == 0 ]; then
echo "user already exists"
else
useradd $user
passwd $user
if [ $? == 0 ]; then
echo "user successfully created"
else
echo "please enter a valid password"
exit 1
fi
fi
fi
elif [ $Entry -eq 2 ]; then
read -p "please enter the user for password change: " existing
if [ -z "$existing" ]; then
echo "username can't be empty"
exit 1
else
sudo passwd $exiting
fi
elif [ $Entry -eq 3 ]; then
read -p "please enter the user name to be deleted: " user2
if [ -z "$user2" ]; then
echo "username can't be empty"
exit 1
else
cat /etc/passwd | grep -i $user2
if [ $? == 0 ]; then
echo "user found"
userdel -r $user2
if [ $? == 0 ]; then
echo "user successfully deleted"
else
echo "user not deleted"
exit 1
fi
else
echo "user not found"
exit 1
fi
fi
else
echo "use only digit 1 or 2"
exit 1
fi