bash if user exists in a group then add
egrep -i "^groupname" /etc/group;
if [ $? -eq 0 ]; then
echo "Group Exists"
else
echo "Group does not exist -- Invalid Group name"
fi
bash if user exists in a group then add
egrep -i "^groupname" /etc/group;
if [ $? -eq 0 ]; then
echo "Group Exists"
else
echo "Group does not exist -- Invalid Group name"
fi
bash if user exists in a group then add
#!/bin/bash
# init
USERID="$1"
#....
/bin/egrep -i "^${USERID}:" /etc/passwd
if [ $? -eq 0 ]; then
echo "User $USERID exists in /etc/passwd"
else
echo "User $USERID does not exists in /etc/passwd"
fi
# ....
bash if user exists in a group then add
egrep -i "^useraccount:" /etc/passwd;
if [ $? -eq 0 ]; then
echo "User Exists"
else
echo "User does not exist -- Invalid Username"
fi
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us