Hi,
I have the following script:
# Inactive Users Removed
#
# Created by: stuaz
# Created on: 16/03/11
#
# This script runs from the Cron
####################################
# Variables
email=blah@blah.com
log=/utils/sdennis/inactiveusers.log
#
# Command to find inactive users and there process numbers
my=`/usr/bin/who -u|/usr/bin/grep -v nppp|/usr/bin/awk '{ if($6>"1:00") print($7
)}'`
# Command to list users in Email
my2=`/usr/bin/who -u|/usr/bin/grep -v nppp|/usr/bin/awk '{ if($6>"1:00") print (
"Username: " $1 " " "Inactive for: " $6)}'`
echo $my
# Send list of inactive users to log file.
echo $my2 > $log
# Email log file
cat $log | mail -s "Inactive Users Removed from the System" $email
# Run deleteuser command to remove inactive users
if [ "$my" ]
then
/u/ud/bin/deleteuser $my >/dev/null 2>&1
fi
All it does is check the "who" for people who have been inactive for the past hour and then emails that list to me. Then with that list it runs the "deleteuser" command which will gracefully log them off.
The problem I have is while this script will work if it finds one user, it will fail and do nothing if it encounters multiple people.
How can I modify this to accept that there may be multiple people who are inactive for an hour and remove them?
Thanks,