usermod

#/bin/bash
cat $1 | while read un gn pw
do
cat /etc/group | egrep $gn
if [ $? = 0 ]; then
echo "group $gn already exists"
else
groupadd $gn
fi
pass=$(perl -e 'print crypt($ARGV[0], "password")' $pw)
cat /etc/passwd | egrep $un
if [ $? == 0 ];then
echo "user $un already exists"
else
useradd -p $pass -g $gn $un
if [ $? == 0 ];then
echo "user $un added"
fi
fi
done

Is it possible to apply usermod command to the code above just like you told me about userdel $un
bt1942Asked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
usermod  -p $pass -g $gn $un
in place of
echo "user $un already exists"
0
 
bt1942Author Commented:
#/bin/bash
cat $1 | while read un gn pw
do
cat /etc/group | egrep $gn
if [ $? = 0 ]; then
echo "group $gn already exists"
else
groupadd $gn
fi
pass=$(perl -e 'print crypt($ARGV[0], "password")' $pw)
cat /etc/passwd | egrep $un
if [ $? == 0 ];then
echo "user $un already exists"
else
useradd -p $pass -g $gn $un
if [ $? == 0 ];then
echo "user $un added"
fi
fi
done


I have about 20user accounts in user.txt file which contains name, groupname, password. However how can i apply usermod command to
Above code to modify 20user accounts name in one shot. For example if i do
./usermod.sh user.txt it will modify all 20 user accounts name in once.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.