Link to home
Start Free TrialLog in
Avatar of bt1942
bt1942

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bt1942
bt1942

ASKER

#/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.