Visit Our UNIX and Linux User Community


Removing Inactive Sessions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing Inactive Sessions
# 1  
Old 03-16-2011
Removing Inactive Sessions

Hi,

I have the following script:
Code:
 
 
# 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,
# 2  
Old 03-16-2011
What is your system? What is your shell? Is it possible to modify deleteuser or must it be done from here?
# 3  
Old 03-16-2011
Quote:
Originally Posted by Corona688
What is your system? What is your shell? Is it possible to modify deleteuser or must it be done from here?
It is AIX, and the shell is /bin/sh. Deleteuser cannot be modified.
# 4  
Old 03-16-2011
Assuming the users have no spaces, this could do:

Code:
[ ! -z "$my" ] && for U in $my
do
        /u/ud/bin/deleteuser $U >/dev/null 2>&1
done

There is a limit on the maximum number of arguments sh can fit in an argument list like that, but unless you have hundreds and hundreds of logins to kill I think the limit should be sufficient.

Previous Thread | Next Thread
Test Your Knowledge in Computers #391
Difficulty: Medium
Darwin, the open source subset of macOS, has behavior that can be set to comply with UNIX 03.
True or False?

7 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Help in Oracle Inactive Sessions

hi , i could see 50-60 oracle inactive session running under my application name, does this cause any issue.. or can this inactive session be excluded , if so how can we reduce them or exclude them , your inputs are much required. my application runs on C++ with oracle , pro*c involved.... (1 Reply)
Discussion started by: senkerth
1 Replies

2. UNIX for Advanced & Expert Users

Find Inactive VG

lsvg -o shows active VGs. Is there a way to find inactive VGs with a command? Please advise. (2 Replies)
Discussion started by: Daniel Gate
2 Replies

3. Shell Programming and Scripting

Getting error while getting status of active and inactive sessions from ORACLE DB

Hi All, I have a written a test script which retrieves the status of active and inactive sessions from oracle DB, but i am receiving error while executing. My script is filepath="/home/ocsg/scripts/db_session_report/current_session_report.txt"... (1 Reply)
Discussion started by: poweroflinux
1 Replies

4. UNIX for Dummies Questions & Answers

Inactive Session

Hi, I am new to forum, I am wondering anyone can help me ? Is there a command to tell whether a particular process is already inactive, so I can issue a kill command to end it. I have been encountering scenerio whereby users always shutdown abnormally by closing the windows, and my application... (12 Replies)
Discussion started by: lowtaiwah
12 Replies

5. UNIX for Advanced & Expert Users

inactive pages

hi, plz tell me, how can get the inactive pages in HP UX. bye.... (1 Reply)
Discussion started by: venkat_t
1 Replies

6. Programming

wired and inactive pages

Hello How to find out wired pages and inactive pages in HP -UNIX. Bye (1 Reply)
Discussion started by: manjunath
1 Replies

7. UNIX for Dummies Questions & Answers

How to logout inactive users????

I would like to automatically logout from the system inactive users depending on their functions. For example there are users that I would like to logout after 15 minutes of inactivity, but there are others that I would like to logout after 30 minutes of inactivity. It's possible to do this??? (6 Replies)
Discussion started by: rrivas
6 Replies

Featured Tech Videos