Sponsored Content
Top Forums Shell Programming and Scripting Write a scripts to kill idle user for 60 min. & email user list to admin in text file Post 302507607 by sumit30 on Thursday 24th of March 2011 10:15:53 AM
Old 03-24-2011
Question Write a scripts to kill idle user for 60 min. & email user list to admin in text file

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)


Code:
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 [[ $(echo "$numbers" | 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

# Send Email notification
# Please suggest email command to email log file to admin email id.
# 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
# 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

Last edited by pludi; 03-24-2011 at 08:27 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

user & group read/write access question

folks; I created a new users on my SUSE box and i need to give this user/group a read write access to one specific folder. here's the details: - I created new user "funny" under group "users". - I need to give this user "funny" a read/write access to another directory that is owned by "root".... (3 Replies)
Discussion started by: Katkota
3 Replies

2. UNIX for Dummies Questions & Answers

Difference between : Locked User Account & Disabled User Accounts in Linux ?

Thanks AVKlinux (3 Replies)
Discussion started by: avklinux
3 Replies

3. UNIX for Advanced & Expert Users

Send email as a different user than the user logged in

Hi I am using mailx to send email and am wondering if there is a way I can send the email from a different user than the user logged in. something like do-not-reply@xyz.com Thank you. (1 Reply)
Discussion started by: rakeshou
1 Replies

4. Shell Programming and Scripting

How to kill process after x idle min?

I need a script to kill those process id whose idle time is more than 30min plz help me (3 Replies)
Discussion started by: salil2012
3 Replies

5. Homework & Coursework Questions

[Scripting]Find & replace using user input then replacing text after

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: (o) Checkout an auto part: should prompt the user for the name of the auto part and borrower's name: Name:... (2 Replies)
Discussion started by: SlapnutsGT
2 Replies

6. Shell Programming and Scripting

User idle time and kill

Hello.. I have many sleepy users on my Solaris box and need to kill them if they are idle for more than 45 minutes for example...I know who -u gives and the idle time but unable to make a awk line to get the condition perfect. Please help...:wall: (9 Replies)
Discussion started by: wimaxpole
9 Replies

7. Shell Programming and Scripting

Script to Send Email to a user when an admin kills process

Can anyone create or give me a script that I can use to email a user automatically when I kill one of their processes? Or Can you give me a script to allow me to email a user (entering email manually) when a process is killed? Like showing what the PID was and a reason the admin killed it? Is... (2 Replies)
Discussion started by: JoeGazz84
2 Replies

8. Shell Programming and Scripting

set only some command & scripts permission to a particular user

hi, i am new in unix.......i am using bash and i want to create a user which has only some command and scripts permission.........is it possible? thanx (1 Reply)
Discussion started by: rakeshtomar82
1 Replies

9. Homework & Coursework Questions

Need to write a script user.sh that parses name & password

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a script called user.sh that parses the name and password of given in a file (user.txt) and creates the user... (1 Reply)
Discussion started by: Nygenesis
1 Replies

10. UNIX for Dummies Questions & Answers

Deletion of list of user based on a text file In LDAP UNIX server

Dear All, It would be really nice, if you could help me to write a script for deletion of list of user( more than 15000 users) stored in a file and sorted by email address( i need deletion of only a particular type of mail address). Is the any script to write and take the file as input and... (3 Replies)
Discussion started by: Chand
3 Replies
rt-email-group-admin(8) 				     Request Tracker Reference					   rt-email-group-admin(8)

NAME
rt-email-group-admin - Command line tool for administrating NotifyGroup actions SYNOPSIS
rt-email-group-admin --list rt-email-group-admin --create 'Notify foo team' --group Foo rt-email-group-admin --create 'Notify foo team as comment' --comment --group Foo rt-email-group-admin --create 'Notify group Foo and Bar' --group Foo --group Bar rt-email-group-admin --create 'Notify user foo@bar.com' --user foo@bar.com rt-email-group-admin --create 'Notify VIPs' --user vip1@bar.com rt-email-group-admin --add 'Notify VIPs' --user vip2@bar.com --group vip1 --user vip3@foo.com rt-email-group-admin --rename 'Notify VIPs' --newname 'Inform VIPs' rt-email-group-admin --switch 'Notify VIPs' rt-email-group-admin --delete 'Notify user foo@bar.com' DESCRIPTION
This script list, create, modify or delete scrip actions in the RT DB. Once you've created an action you can use it in a scrip. For example you can create the following action using this script: rt-email-group-admin --create 'Notify developers' --group 'Development Team' Then you can add the followoing scrip to your Bugs queue: Condition: On Create Action: Notify developers Template: Transaction Stage: TransactionCreate Your development team will be notified on every new ticket in the queue. USAGE
rt-email-group-admin --COMMAND ARGS COMMANDS
list Lists actions and its descriptions. create NAME [--comment] [--group GNAME] [--user UNAME] Creates new action with NAME and adds users and/or groups to its recipient list. Would be notify as comment if --comment specified. add NAME [--group GNAME] [--user UNAME] Adds groups and/or users to recipients of the action NAME. delete NAME Deletes action NAME if scrips doesn't use it. switch NAME Switch action NAME from notify as correspondence to comment and back. rename NAME --newname NEWNAME Renames action NAME to NEWNAME. NOTES If command has option --group or --user then you can use it more then once, if other is not specified. AUTHOR
Ruslan U. Zakirov <ruz@bestpractical.com> SEE ALSO
RT::Action::NotifyGroup, RT::Action::NotifyGroupAsComment perl v5.14.2 2013-05-22 rt-email-group-admin(8)
All times are GMT -4. The time now is 05:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy