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
FAILLOG(8)						    System Management Commands							FAILLOG(8)

NAME
faillog - display faillog records or set login failure limits SYNOPSIS
faillog [options] DESCRIPTION
faillog displays the contents of the failure log database (/var/log/faillog). It can also set the failure counters and limits. When faillog is run without arguments, it only displays the faillog records of the users who had a login failure. OPTIONS
The options which apply to the faillog command are: -a, --all Display (or act on) faillog records for all users having an entry in the faillog database. The range of users can be restricted with the -u option. In display mode, this is still restricted to existing users but forces the display of the faillog entries even if they are empty. With the -l, -m, -r, -t options, the users' records are changed, even if the user does not exist on the system. This is useful to reset records of users that have been deleted or to set a policy in advance for a range of users. -h, --help Display help message and exit. -l, --lock-secs SEC Lock account for SEC seconds after failed login. Write access to /var/log/faillog is required for this option. -m, --maximum MAX Set the maximum number of login failures after the account is disabled to MAX. Selecting a MAX value of 0 has the effect of not placing a limit on the number of failed logins. The maximum failure count should always be 0 for root to prevent a denial of services attack against the system. Write access to /var/log/faillog is required for this option. -r, --reset Reset the counters of login failures. Write access to /var/log/faillog is required for this option. -t, --time DAYS Display faillog records more recent than DAYS. -u, --user LOGIN|RANGE Display faillog record or maintains failure counters and limits (if used with -l, -m or -r options) only for the specified user(s). The users can be specified by a login name, a numerical user ID, or a RANGE of users. This RANGE of users can be specified with a min and max values (UID_MIN-UID_MAX), a max value (-UID_MAX), or a min value (UID_MIN-). When none of the -l, -m, or -r options are used, faillog displays the faillog record of the specified user(s). CAVEATS
faillog only prints out users with no successful login since the last failure. To print out a user who has had a successful login since their last failure, you must explicitly request the user with the -u flag, or print out all users with the -a flag. FILES
/var/log/faillog Failure logging file. SEE ALSO
login(1), faillog(5). System Management Commands 06/24/2011 FAILLOG(8)
All times are GMT -4. The time now is 07:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy