#----------------------------------------------------
# create the user
#----------------------------------------------------
NEWLOGIN=try1
mkuser pgrp=staff groups=staff gecos="user name" home=/home/$NEWLOGIN login=true shell=/usr/bin/ksh $NEWLOGIN
if [ $? -ne 0 ]
then
echo "login $NEWLOGIN not created "
exit 1
fi
#----------------------------------------------------
# crypt the password for newlogin and add the stanza
# in /etc/security/passwd for AIX
#----------------------------------------------------
PASSWORD_FILE=/etc/security/passwd
PASSWORD=$NEWLOGIN # assign the login to the password
type perl 1>/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "perl not available in your PATH, please type in password"
pwdadm $NEWLOGIN
else
perl generate_crypted_pass.pl $PASSWORD_FILE $NEWLOGIN $PASSWORD
if [ $? -ne 0 ]
then
echo "error in generating crypted password"
echo "please type in password for $NEWLOGIN"
pwdadm $NEWLOGIN
fi
# clear the flags for newlogin, so it is not prompted to
# change the password at first telnet connection
pwdadm -c $NEWLOGIN
fi
exit 0
#
#end of korn shell script that calls perl script
#
#
# begin of perl script named "generate_crypted_pass.pl "
# for generating crypted password
#
#-------------------------------------------------------------
# perl script for crypting readable password and writing
# the stanza in file passed as first parameter
#-------------------------------------------------------------
#!/usr/bin/perl
if ( $#ARGV < 2 ){
print "Usage : $0 <password file> <login> <readable password>\n";
die;
}
use POSIX;
$ENV{'TZ'} = "GMT";
#-------------------------------------------------------------
# get parameters
#-------------------------------------------------------------
$password_file=@ARGV[0];
$login=@ARGV[1];
$readable_password=@ARGV[2];
#-------------------------------------------------------------
# generate 2 chars ASCII for salt randomly in the set
# [./0-9A-Za-z]
#-------------------------------------------------------------
# concatenate the 2 chars to make salt
$salt="$c1$c2";
# crypt the readable password
$crypted_password = crypt($readable_password,$salt) ;
# generate last modification time of password since epoch
$last_pass_change = POSIX::time() ;
#-------------------------------------------
# write the stanza in the password file
#-------------------------------------------
open (OUT, ">>$password_file" || die "cannot open $password_file: $!.\n";
print OUT<<EOF;
$login:
password = $crypted_password
lastupdate = $last_pass_change
flags =
EOF
exit 0
#
#end of perl script for generating crypted password
#
This is what I came up with. The problem I am having is that if a user enters the loginid i upper case. How would I convert it to lower case?
!/bin/ksh
echo Enter user login with no special characters and no longer than 8 characters and all lower case. Example: jsmith
echo Enter user login
read loginID
echo Enter user information: Example: Joe Smith
read username
echo Enter Group information: Example: staff
read group
echo Enter groups used by the user seperated by commas: Example: staff,dba,accounting
read groups
grep $loginID /etc/passwd
if [ $? -ne 1 ]
then
echo 'already in system '
else
echo "Adding user..." $loginID
mkuser pgrp="$group" groups="$groups" gecos="$username" shell="/usr/bin/ksh" home="/home/$loginID" $loginID
echo "Making user directory..." $loginID
mkdir /usr/$loginID
chown $loginID:$group /home/$loginID
echo "Setting unix users password for " $loginID
passwd $loginID
echo "Set password..."
fi
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.