Shell Script to add user and password using files as an input (need 2 files – if best)

=======Handy to create a multiple users in a fly===========

Create Users using file containing List of Users/Password/Description with comma separated===========
There are two files (users.txt and users.sh) with a shell script and users (users.sh ) list.

users.txt file contains the “<username>,<password>,<User_detail>”

[root@station1 test2]# vi users.txt

=======================
user100,password100,User1_Staff
user200,password200,User2_Staff
user300,password300,User3_Staff
=========================
[root@station1 test2]# cat users.sh
#!/bin/sh
#for line in `more sortdetails.txt`
for line in `more users.txt`
# while read line
do
username=`echo $line | cut -d’,’ -f1`
password=`echo $line | cut -d’,’ -f2`
name=`echo $line | cut -d’,’ -f3`
#echo $username $password $name
/usr/sbin/useradd -c $name -p $password $username
echo $password > pw
cat pw | passwd –stdin $username
done
exit 1
==================
root@station1 test2]# chmod a+x users.sh
[root@vmail01 test2]# sh users.sh

======Enjoy============

Comments are closed.

Videos, Slideshows and Podcasts by Cincopa Wordpress Plugin

364085