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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.