Topic
  • 2 replies
  • Latest Post - ‏2011-03-28T17:17:28Z by kashyap30
kashyap30
kashyap30
2 Posts

Pinned topic Script for killing idle user and emailing user list to admin

‏2011-03-24T14:48:22Z |
Folks,

I have written one script for following condition by referring some of online post in this forum. Please correct it if I'm missing something in it. (OS: AIX 5.3)

1. List the idle user. (I used whoidle command to list first 15 user and get username, idle time, pid and login time). Any other suggestion to get all the user at once including above things?
2. Exclude few users from list (system user and admin user)
3. Calculate idle time(if user is more than 60 min idle)
4. Make entry of that user in log file (If possible I want to create text file)
5. Email log file to admin
6. Sleep for 5 min. after emailing total list of user to admin
7. Kill the users in list
8. Loop it to reach next 15 users. (If possible I want to get rid of this condition by following all idle user list command with pid's)

IDLE_USER=/tmp/idleusers.log
idletimeslist=$(whoidle | awk '{print $4}')
maxidletime = 0:59

idletimes= $(grep -v^"root|daemon|bin|sys|adm|nobody|abc|pqr" $idletimeslist)
for numbers in $idletimes;do

if [ grep : ) == $maxidletime];then
getline=$(whoidle | grep $numbers)
user=$(echo $getline | awk '{print $1}')
processid=$(echo $getline | awk '{print $5}')
started=$(echo $getline | awk '{print $3}')
echo $user' '$processid' '$started' '$number >> $IDLE_USER
fi
done

  1. Send Email notification
  2. Please suggest email command to email log file to admin email id.
  3. Also can I convert log file to text file? (word file)

sleep 300

pidlist= awk '{print $2}' $IDLE_USER
for pid in $pidlist;do
kill $pid
done
  1. I have no idea how I can loop it to satisfy condition '8'. Do i need true or false flag #for it?
I need to put this code in production as soon as possible.
Expert please throw some light on it.
Thanks in advance.
Sumit
Updated on 2011-03-28T17:17:28Z at 2011-03-28T17:17:28Z by kashyap30
  • SystemAdmin
    SystemAdmin
    549 Posts

    Re: Script for killing idle user and emailing user list to admin

    ‏2011-03-24T18:50:57Z  
    just curious: did you think up this stuff for yourself or was this an assignment?
  • kashyap30
    kashyap30
    2 Posts

    Re: Script for killing idle user and emailing user list to admin

    ‏2011-03-28T17:17:28Z  
    just curious: did you think up this stuff for yourself or was this an assignment?
    I need to put this code into production server ... not a assignment.