###
### The shell Script is used for AIX System Management
### The shell Script should use with Tivoli FrameWork
###
### Author:BanHao
### VER:V1.0
###
#!/usr/bin/ksh
###
### user_manager
###
user_manager()
{
clear
while true
do
echo "********************************************************"
echo "* *"
echo "* *"
echo "* 1)|ADD USER *"
echo "* *"
echo "* 2)|DEL USER *"
echo "* *"
echo "* q)|quit *"
echo "* *"
echo "********************************************************"
echo " Please enter your choice: \c";read X1
case $X1 in
1)
echo "Please Enter the User Name: \c";read USERNAME
echo "Please Enter the User ID: \c";read USERID
echo "Please Enter the Primary GROUP: \c";read PGROUP
echo "Please Enter the Group SET: \c";read GROUPS
echo "Please Enter the HOME Directory: \c";read HOMEDIRECTORY
echo "Please Enter the shell: \c";read SH
echo "mkuser id='$USERID' pgrp='$PGROUP' groups='$GROUPS' home='$HOMEDIRECTORY' shell='$SH' $USERNAME" |sed "s/[^ ]*=''//g" > ./shell/add_user.sh
echo "echo "$USERNAME:passw0rd"|chpasswd" >> ./shell/add_user.sh
wcrttask -t add_user -l Aix_System_TL -i aix4-r1 SERVERNAME /DIRECTORY/aix_manager/shell/add_user.sh -r admin
host_manager
cat host|while read line
do
wruntask -t add_user -l "Aix_System_TL" -h $line
done
rm ./shell/add_user.sh
wdeltask add_user "Aix_System_TL"
;;
2)
echo "Please Enter the User Name: \c";read USERNAME
echo "rmuser $USERNAME" > ./shell/del_user.sh
wcrttask -t del_user -l Aix_System_TL -i aix4-r1 SERVERNAME /DIRECTORY/aix_manager/shell/del_user.sh -r admin
host_manager
cat host|while read line
do
wruntask -t del_user -l "Aix_System_TL" -h $line
done
echo "Do your want to Clear the user's Home Directory?[Y/N] \c";read YN
if [ "$YN" = y -o "$YN" = Y ]
then
host_manager
cat host|while read line
do
wruntask -t clear_home_dir -l "Aix_System_TL" -h $line
done
fi
rm ./shell/del_user.sh
wdeltask del_user "Aix_System_TL"
;;
q)
clear
echo "********************************************************"
echo "* *"
echo "* Thank You! *"
echo "* *"
echo "********************************************************"
break;;
*)
clear
echo "********************************************************"
echo " Sorry, $X1 is not the right choice! "
echo " "
echo " Please enter the right Choice "
echo "********************************************************"
echo
continue;;
esac
done
}
###
### user_audit
###
user_audit()
{
host_manager
cat host|while read line
do
wruntask -t get_lastlog -l "Aix_System_TL" -h $line
done
mv /tmp/*.lastlog ./data
mv /tmp/*.user ./data
mv /tmp/*.securitypasswd ./data
mv /tmp/*.passwd ./data
cd data
ls -la *.passwd|awk '{print $9}' > passwdfile.tmp
cat passwdfile.tmp|while read line
do
HOSTNAME=`echo $line|awk -F. '{print $1}'`
#echo $HOSTNAME
#echo $HOSTNAME.passwd.tmp
#echo $HOSTNAME.lastlog
#echo $HOSTNAME.lastupdate.log
awk -F: '{print $1}' $line > $HOSTNAME.passwd.tmp
cat $HOSTNAME.passwd.tmp|while read USER
do
echo $USER >> $HOSTNAME.lastupdate.log
../shell/lastupdate.sh $USER $HOSTNAME.securitypasswd >> $HOSTNAME.lastupdate.log
echo "********************************************************" >> $HOSTNAME.lastupdate.log
done
done
#rm *.lastlog
#rm *.passwd
#rm *.tmp
}
###
### host_manager
###
host_manager()
{
while true
do
cat host
echo "Do you want to running in ALL these Hosts?[Y/N] \c";read YN
if [ "$YN" = y -o "$YN" = Y ]
then
break
else
echo "Do you want to add Host?[Y/N] \c";read YN
if [ "$YN" = y -o "$YN" = Y ]
then
echo " Please Enter the Host Name: \c";read HOSTNAME
if [ $HOSTNAME ]
then
clear
echo $HOSTNAME >> host
cat host > host.tmp
cat host.tmp | sort -nk1 |tee host
else
echo "The Host Name can not be Blank!"
fi
rm -rf host.tmp
else
echo "Do you want to del Host?[Y/N] \c";read YN
if [ "$YN" = y -o "$YN" = Y ]
then
echo "Please Enter the Host Name: \c";read HOSTNAME
if [ $HOSTNAME ]
then
clear
sed '/'"$HOSTNAME"'/d' host > host.tmp
cat host.tmp | sort -nk1 |tee host
else
echo "The Host Name can not be Blank!"
fi
rm -rf host.tmp
fi
fi
fi
clear
echo "These Hosts will running the task!"
cat host
echo "*************The End****************"
done
}
###############################################################
###
### MAIN PROGRAM
###
clear
while true
do
echo "********************************************************"
echo "* *"
echo "* *"
echo "* 1)|USER MANAGER *"
echo "* *"
echo "* 2)|USER AUDIT *"
echo "* *"
echo "* q)|quit *"
echo "* *"
echo "********************************************************"
echo " Please enter your choice: \c";read X1
case $X1 in
1)user_manager;;
2)user_audit;;
q)
clear
echo "********************************************************"
echo "* *"
echo "* Thank You! *"
echo "* *"
echo "********************************************************"
break;;
*)
clear
echo "********************************************************"
echo " Sorry, $X1 is not the right choice! "
echo " "
echo " Please enter the right Choice "
echo "********************************************************"
echo
continue;;
esac
done