Issue
I have a list of users in a file ( America, Belgium, India, Srilanka, Bhutan)
I need to run a script on each machine to check the above users exist, if its does not, create those users,
users are on file resides in /etc/users.txt
Contents of users.txt
America
Belgium
India
Srilanka
Bhutan
I tried this, but it’s not checking users on my list of files.
#!/bin/sh
if grep -q "^$1:" /etc/users.txt ;then
echo exists
else
echo FALSE
fi
Solution
-
you didnt call users.txt, you just called users
-
you have a bunch of incorrect regex in your grep
-
(optional) you should use -i on grep to accept lowercase letters
#!/bin/sh if grep -i -q "$1" /etc/users.txt ;then echo exists else echo FALSE fi
Answered By – Taylor TEK
Answer Checked By – Katrina (BugsFixing Volunteer)