Operating System - Linux
1827854 Members
1537 Online
109969 Solutions
New Discussion

Re: script for logging off users who are idle

 
SOLVED
Go to solution
John Jimenez
Super Advisor

script for logging off users who are idle

For security and license limitation reasons,We are trying to figure out a script to log off users who are idle. But we are having trouble figuring out "pid t". Is anyone there familiar with this or other function calls that might be needed to complete this? Or better yet if someone has already written a similar script already?
Thanks again for any help

John
Hustle Makes things happen
20 REPLIES 20
Sandman!
Honored Contributor

Re: script for logging off users who are idle

Assuming you mean "pid_t" which is a signed integer variable, then here is a brief summary of it.

The pid_t data type represents process IDs. You can get the process ID of a process by calling getpid. The function getppid returns the process ID of the parent of the current process (this is also known as the parent process ID or PPID).

Your program should include the header files `unistd.h' and `sys/types.h' to use these functions.

cheers!
Tom Schroll
Frequent Advisor

Re: script for logging off users who are idle


Are you trying to do this with a script or with a "C" program?

Some shells have an autologout feature as well.

-- Tom
If it ain't broke, it needs optimized.
Rick Garland
Honored Contributor

Re: script for logging off users who are idle

Has the TMOUT variable been looked at.
This value can be set to do just that.

Can be in the /etc/default/security file as well.
John Jimenez
Super Advisor

Re: script for logging off users who are idle

Tom,
Either way a script or "C".

Rick,
I will take a look at the TMOUT variable.
Thanks again I will be assining points later. Any other info or tips are greatly appreciated.
Hustle Makes things happen
John Jimenez
Super Advisor

Re: script for logging off users who are idle

Rick,
TMOUT = 0
Let me find out what this means
Hustle Makes things happen
Gopi Sekar
Honored Contributor

Re: script for logging off users who are idle


TMOUT variable (which i believe specific to BASH shell) if set to above zero in an interactive shell, the value is interpreted as the number of seconds to wait for input after issuing the primary prompt. Bash terminates after waiting for that number of seconds if input does not arrive.

but if your user is in some other program invoked in shell (like vi) then TMOUT will never occur. in that case you have to use some script to achieve this. check the output of w command, it gives IDLE time of a shell. it may be useful for u


Regards,
Gopi
Never Never Never Giveup
John Jimenez
Super Advisor

Re: script for logging off users who are idle

Thank you Gopi. Unfortunately all my users are in a application 99% and rarely in a unix prompt. When they are they are in a posix shell. I changed the the TMOUT on my account from 0 to 10. and left it sitting on a menu of our application. So far nothing has happened.
The w command is interesting. If I am on a prompt it records. But if I am in the menu screen of my application, it does not. But I notice a few logins are actually logging in "IDLE" time. I logged into a menu screen on my application for 10 minutes and my login is still showing "null" in this field.
Hustle Makes things happen
Rick Garland
Honored Contributor

Re: script for logging off users who are idle

A lot of these idle timeouts within the application are configured within the application. Some applications you may not be able to configure.

Example, the TMOUT variable will work on idle shell sessions. If I am sitting at a $ prompt for 60 minutes, then kill me.
Now if I invoke a vi session, I can sit there for 60 minutes and I will not be TMOUT.

If users are not in a shell session, then investigate the app for these idle sessions.

Pat Lieberg
Valued Contributor

Re: script for logging off users who are idle

In my previous job, I had a similar situation to this. We had a limited number of licenses and users were leaving themselves idle in the application. I wrote a shell script that found who was running the application, then coorelated that to the out put of 'who -Hu' and sent email to the users (I wanted to just kill their session, but was overruled by management).

If you'd like to see the script, let me know. It was written for AIX and the ksh shell so should be easily adapted to hp-ux.
John Jimenez
Super Advisor

Re: script for logging off users who are idle

Pat,
Yes if you would not mind, could you e-mail it to jimenez-j@iehp.org?
Hustle Makes things happen
Fabio Ettore
Honored Contributor

Re: script for logging off users who are idle

Hi John,

I don't know scripts to logout users who are idle.
Anyway a possible solution is keepalive parameters.

ndd -h | grep -i keepalive

You will see more details by

ndd -h

Hope this helps you.

Best regards,
Fabio
WISH? IMPROVEMENT!
John Jimenez
Super Advisor

Re: script for logging off users who are idle

Thanks for the help, But I will have to find another way. The sessions sitting in the app never go into an idle state even though they are not doing anything.
Hustle Makes things happen
Mel Burslan
Honored Contributor

Re: script for logging off users who are idle

I do not know the nature of your application but when they run, i.e., not sit idle on the screen, if they accumulate CPU time for the shell they are running under, you can collect this information by the help of ps and awk commands and decide who is idle and who is depending on the accumulated cpu time per process. Just a wild idea.
________________________________
UNIX because I majored in cryptology...
Tom Schroll
Frequent Advisor

Re: script for logging off users who are idle

Well, if you are NOT at a shell prompt (which eliminates the ability to use autologout in tcsh for example), then I suggest a C program that runs as a background system process (daemon), reads the utmp file to get the tty for each user logged into the system, and then do a stat() on the device file to get the last timestamp (indicating activity on the tty). I think this is how the "idle" output of the "w" command is determined. I already have a program written in "C" to "watch" users who log in and out. With some work, it could be adapted to look for idle users, and then kill the session. It has not been tested on HP-UX greater than 11.0 though. Let me know if you are interested. The project spans more than one "C" file though...so I can't really post it here. I could possibly make these additions in my spare time, but I can't guarantee how long it would take for me to finish. :-) I hope that you or someone else can use the info that I provided above to write your own version.
:-) Good luck!

-- Tom
If it ain't broke, it needs optimized.
John Jimenez
Super Advisor

Re: script for logging off users who are idle

Tom,

I am the Admin here. Max, who is the programmer, is not here today. Would it be to much to ask you to send me what you have already. I am sure that he can modify it accordingly. If so my email adress is Jimenez-J@iehp.org

Thanks again,
John
Hustle Makes things happen
Juan M Leon
Trusted Contributor
Solution

Re: script for logging off users who are idle

Hi John try "idled", it is a freeware with C source, your programer can modify and compile it according to your company needs.
http://www.darkwing.com/idled/
Tom Schroll
Frequent Advisor

Re: script for logging off users who are idle

John,

I took a quick look at "idled" and it actually seems to do exactly what you need. So take a look. If you have trouble getting it to work or still need me to send you the code that I have (which would need modification to do what you need), let me know. Take care.

-- Tom
If it ain't broke, it needs optimized.
Juan M Leon
Trusted Contributor

Re: script for logging off users who are idle

Something to Add to Tom Schroll, If I am correct, after you download the source code the default make file is set to be used on SUN OS, you will need to comment that section and uncomment the HP section. after that you can compile and install the software.

Thanks

Juan
Gordon  Morrison
Trusted Contributor

Re: script for logging off users who are idle

Try this:

#!/bin/ksh
who -u | cut -c 1-10,38-50 | egrep "[12][0-9]:|old" > /var/tmp/current
for IDLE_USR in `cat /var/tmp/current | awk '{print $3}'`
do
# kill -9 $IDLE_USR
echo $IDLE_USR
done


This will kill any login shell where the user has not typed anything for 10 hours or more.
When you've tried it out and are happy that it is choosing the right processes to kill, remove the comment from the kill line and delete the echo line.

Share And Enjoy
What does this button do?
John Jimenez
Super Advisor

Re: script for logging off users who are idle

Sorry for not responding to this sooner, another project came up. Juan, My programmer reviewed the code of "idled" and was impressed. We are planning to set it up on Tuesday. Tom if we have any troubles I would appreciate the modifications that you have.

Gordon, 99% of the users are in an application that never goes to "old" even after days of not being used.

Thanks again guys I will let you know if I have issues.
Hustle Makes things happen