-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path32_user_present.sh
34 lines (29 loc) · 936 Bytes
/
32_user_present.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
<<Documentation
NAME : V.Karthikeyan
DATE : 15.05.2021
DESCRIPTION : Script to search a user present in your system
INPUT : ./32_user_present.sh root
OUTPUT : root is present
Documentation
#!/bin/bash
array=($(cat /etc/passwd | cut -d ":" -f 1)) #user name is taken from etc/passwd
total=${#array[@]} #length of array
if [ $# = 0 ] #If no arguments passed, print the error msg and exit
then
echo "Please pass the argument through command line"
exit
fi
check=0
for i in `seq 0 $(($total-1))`
do
if [[ $1 == "${array[i]}" ]] #COMPARING TWO STRINGS ( GIVEN INPUT THROUGH CMD LINE ARG VS ALL ARRAY ELEMENTS )
then
echo "$1 is present " #PRINTING THWE GIVEN ELEMENT IS PRESENT OR NOT
else
check=$((check+1))
fi
done
if [ $check -eq $total ] #Checking count value, if it is equal to length of array the user not present
then
echo "$1 not present"
fi