Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding users in AIX scripts

Status
Not open for further replies.

mabandrew

Technical User
Oct 3, 2003
4
0
0
US
Does anyone have any scripts for adding users to AIX?
 
There are a couple of scripts in this thread: thread52-610651
 
#
#korn shell script that calls perl script
#

#----------------------------------------------------
# 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 &quot;Usage : $0 <password file> <login> <readable password>\n&quot;;
die;
}
use POSIX;
$ENV{'TZ'} = &quot;GMT&quot;;
#-------------------------------------------------------------
# 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]
#-------------------------------------------------------------

# generate first char

$hazard= int(rand()*100) + 26;
$c1=chr($hazard);
while ( $c1 !~ &quot;[./0-9A-Za-z]&quot; ) {
$hazard= int(rand()*100) + 26;
$c1=chr($hazard);
}
# generate 2nd char
$hazard= int(rand()*100) + 26;
$c2=chr($hazard);
while ( $c2 !~ &quot;[./0-9A-Za-z]&quot; ) {
$hazard= int(rand()*100) + 26;
$c2=chr($hazard);
}


# concatenate the 2 chars to make salt
$salt=&quot;$c1$c2&quot;;

# 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, &quot;>>$password_file&quot;) || die &quot;cannot open $password_file: $!.\n&quot;;
print OUT<<EOF;
$login:
password = $crypted_password
lastupdate = $last_pass_change
flags =

EOF
exit 0
#
#end of perl script for generating crypted password
#


 
This looks very good!!

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 &quot;Adding user...&quot; $loginID
mkuser pgrp=&quot;$group&quot; groups=&quot;$groups&quot; gecos=&quot;$username&quot; shell=&quot;/usr/bin/ksh&quot; home=&quot;/home/$loginID&quot; $loginID
echo &quot;Making user directory...&quot; $loginID
mkdir /usr/$loginID
chown $loginID:$group /home/$loginID
echo &quot;Setting unix users password for &quot; $loginID
passwd $loginID
echo &quot;Set password...&quot;
fi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top