I need to lockout about 250 user accounts on a server. I figure on putting the user accounts to be locked out in a text file and the running a script to go through the file and run the "passwd -l useraccount" against the /etc/passwd file (yes, I am root as I do this).
Here is what I have so far:
#!/bin/sh
# BE CAUTIOUS!! This will modify the /etc/passwd file to lockout terminated
# employee accounts using the 'passwd -l useraccount' command.
# copy this to servername under the /etc directory. Make sure the
# text file that has the user accounts to be deleted is also copied to servername.
# create variables
TERMED="terminated"
# LOCATION_EMAIL="myemail@mycompany.com"
for GONE in `/etc/seeya`
do
echo "**********************************" > $TERMED
passwd -l $GONE
echo "This user account, "$GONE", is locked on `date +%m/%d/%y`." >> $TERMED
echo " " >> $TERMED
(do I put a 'done' statement here?)
#mail results of TERMED
#cat $TERMED |uuencode $GONE.wri | mailx -s "$GONE account locked" $LOCATION_EMAIL
# delete TERMED to make room for next on list.
# rm $TERMED
It seems pretty simple, but what if there is a useraccount in my list, but not in the /etc/passwd file? or vice-versa? other error messages?
Also, is my email statement right? I don't want 200+ individual emails, just one email showing the contents of $TERMED.
Thanks for the help.