summary:script address:[Fwd: RE: sript for passwd]

From: Geetha Thanu <geeta_at_cdfd.org.in>
Date: Wed Dec 07 2005 - 21:24:57 EST
Hello all,

This is another script from Billy shaw.
regds
geetha

---------------------------- Original Message ----------------------------
Subject: RE: sript for passwd
From:    "Billy Shaw" <billy@sceneunseen.com>
Date:    Tue, December 6, 2005 10:44 pm
To:      geeta@cdfd.org.in
--------------------------------------------------------------------------

Here is something you could possibly put into your script.
The entries should be tab separated input file with the
following columns:

Username	FirstName	LastName	Password
Billy		Billy		Shaw		foobar


I just put this together quickly and it depends on having apache
installed. Apache provides the htpasswd command which can encrypt 
plaintext using cyrpt and provide the otuput to STDOUT.
This is not tested so be sure you have a good backup before using..  and
use at your own risk. You may want to also add a lot more error  checking.

#!/bin/sh

INPUTFILE=/var/tmp/userlist.txt
HOMEDIRBASE=/export/home
DEFAULTGROUP=users

# For tab seperated files, make tab the Input field seperator
IFS=`echo t | tr t '\t'`

useradd -D -b ${HOMEDIRBASE} -g ${GROUP}

cat ${INPUTFILE} | while read USERNAME FIRSTNAME LASTNAME PASSWORD do
 	FULLNAME="${FIRSTNAME} ${LASTNAME}"
 	echo "Creating account for ${FULLNAME} (${USERNAME})"
 	useradd -c ${FULLNAME} -m ${USERNAME}

 	# use apache's htpasswd to cyrpt the desired password
 	CRYPTEDPASSWORD=`/usr/apache/bin/htpasswd -bdn ${USERNAME}
${PASSWORD} | awk -F: '{print $2}'`
 	# Update the shadow entry for this user
 	sed "s#${USERNAME}:\*LK\*:${USERNAME}:${CRYPTEDPASSWORD}#g' <
/etc/shadow > /var/tmp/shadow.tmp

 	# Maybe some simple error checking to see that we got what we
tried to do.
 	my UPDATEDSHADOWENTRY=`tail -1 /var/tmp/shadow.tmp | awk -F:
'{print $2}'`
 	if [ "${CRYPTEDPASSWORD}" = "${UPDATEDSHADOWENTRY}" ]
 	then
 		mv /var/tmp/shadow.tmp /etc/shadow
 		chown root:sys /etc/shadow
 		chmod 400 /etc/shadow
 	else
 		echo "Error updating shadow entry for ${FULLNAME}
(${USERNAME})"
 	fi
done


Regards,
Billy-



-- 
Geetha Thanu
Bioinformatics
CDFD
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Thu Dec 8 09:21:46 2005

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:53 EST