#!/bin/csh -f # # reads /root/users.txt as input # K. Inscoe - June 7, 2005 # # Globals set file = "/root/users.txt" set tmpone = "/root/usersone.tmp" set tmptwo = "/root/userstwo.tmp" set group = "cvs" set unit = "CVS Users" # Clean up if ( -e $tmpone ) rm -f $tmpone if ( -e $tmptwo ) rm -f $tmptwo # Prepare the file # Remove leading spaces sed -e 's/^ *//' < $file > $tmpone # remove trailing spaces sed -e 's/ *$//' < $tmpone > $tmptwo rm -f $tmpone # Reduce white space down to one character sed -e 's/ / /;s/ / /;s/ / /' < $tmptwo > $tmpone rm -f $tmptwo # Convert spaces between first and last name to a "+" for a delimiter later... sed -e 's/ /\+/' < $tmpone > $tmptwo rm -f $tmpone # Remove all hyphenatations and back-ticks from names sed -e "s/\-//;s/'//" < $tmptwo > $tmpone rm -f $tmptwo # Process the file line by line foreach name ( `cat $tmpone`) # Create a pretty name for gecos field set pretty = `echo $name | sed 's/\+/ /'` # Convert to all lowercase set fullname = `echo "$name" | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` # Set the login id set first = `echo $fullname | awk -F+ '{ print $1}' | cut -c1` set last = `echo $fullname | awk -F+ '{ print $2}' | cut -c1-12` set loginid = `echo $first``echo $last` # First check to see if user exists already id $loginid >& /dev/null set ret = $status if ( $ret == 0 ) then echo "Login for $loginid already exists" else # Generate a random passwd set passwd=`/usr/local/bin/pwgen -c -n -N 1` # Convert to crypt set crypt=`/bin/echo $passwd | /usr/local/bin/pwcrypt -q` # Add the user echo "Creating user: $loginid [$pretty] - Password is: $passwd" /usr/sbin/useradd -c "`echo $pretty`, $unit" -d /home/$loginid -m -s /bin/ksh -g $group -p $crypt $loginid /usr/bin/finger $loginid echo "-------------" endif end # Clean up rm -f $tmpone exit