[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

usermod

Posted on 2012-09-16
2
Medium Priority
?
1,001 Views
Last Modified: 2012-09-18
#/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
0
Comment
Question by:bt1942
2 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 1000 total points
ID: 38403156
usermod  -p $pass -g $gn $un
in place of
echo "user $un already exists"
0
 

Author Comment

by:bt1942
ID: 38404254
#/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

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month18 days, 13 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question