Ending user sessions which have been on a program for longer than 1 hour


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ending user sessions which have been on a program for longer than 1 hour
# 1  
Old 08-09-2012
Ending user sessions which have been on a program for longer than 1 hour

hi,

im looking to write a script to end user sessions which are on a paticular program and have been for over an hour so I can free up the system a bit.
I understand that the "who" command lists the current users logged into the system, however it does not let me see what program they are on and how long they have been on it.

If i do a
Code:
ps -ef | grep <username>

then this does provide me with the information I need, question is how do I get it to grep not just one username but every user that is logged into the system currently.

Any help would be massively appreciated
# 2  
Old 08-09-2012
from the who command get the user logged in and save in file and from ps -ef get the processes running for more than hours and use grep -f saved_file for the processes of user currently logged in.
# 3  
Old 08-09-2012
Code:
ps -eo user,cmd,start_time

will output a list like
Code:
JohnF     cat         15:00

You could grep for your progname and have what you requested for.
This User Gave Thanks to RudiC For This Post:
# 4  
Old 08-09-2012
Cheers RudiC Smilie
My ps doesnt like those formats so Ive decided to go along with this which gives me what I require thing is now I don't know how I can kill the user off using the PID without any intervention.
Code:
ps -aef | grep Aug | grep me1010

The PID for the user is in the third column along

---------- Post updated at 09:00 AM ---------- Previous update was at 08:59 AM ----------

This is the output of the command Ive just mentioned, PID is in the third column
Code:
rigbyt  4766  4607   0   Aug 08 pts/124     0:05 /apps/progress//bin/_progres -p me1010rf.p -pf /apps/live/awards/data/awards.pf

# 5  
Old 08-09-2012
As root you can issue kill PID which will send the default TERM (#15) to that process. If that doesn't work, issue kill -9 PID which cannot be blocked by the receiving process. It may be neccessary to inform users beforehand, e.g. using write user.

Does your ps not allow for any formatting/column selection?
# 6  
Old 08-09-2012
this is the format of the ps command I currently have,

Quote:
'format' is one or more of:
user ruser group rgroup uid ruid gid rgid pid ppid pgid sid taskid ctid
pri opri pcpu pmem vsz rss osz nice class time etime stime zone zoneid
f s c lwp nlwp psr tty addr wchan fname comm args projid project pset
Yes thats a good idea Ill incorportae that in the script somewhere
# 7  
Old 08-09-2012
Did you try the user,stime,comm format selectors? Or fname?
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk program date function no longer running

I work at a company that uses a program written in AWK to track various data and prepare reports. Worked with this program for three years plus (the author is no longer with us) and the YTD Production report will not return a report with a date after 123119. This is a problem. Below is the (I... (3 Replies)
Discussion started by: paulgdavitt
3 Replies

2. UNIX for Beginners Questions & Answers

Find number of ACTIVE SSH putty sessions, excluding where the user hopped on to a diff server

Hi - If iam logged on to server A, on 4 putty windows using SSH ... and out of these 4 logged-in sessions, in one of the sessions if i did SSH from server A to server B; i would now have 4 putty windows sessions ... of which 3 are actively logged on to Server A while 1 putty window is actively... (2 Replies)
Discussion started by: i4ismail
2 Replies

3. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

4. Shell Programming and Scripting

Removing old user directories that are no longer Users in /etc/passwd

I am new to shell scripting, and have not done much programming in several years. So I am very rusty at this at best. I know my way around the linux command line, but actually scripting is something I have not done too much of. I have been tasked to come up with a script that will pull all... (5 Replies)
Discussion started by: shuiend
5 Replies

5. UNIX for Advanced & Expert Users

Logging User Sessions

Hello, I am using a Linux server (Ubuntu 11.04 Server) to host some files and a code repository. Because we are using ssh + svn to connect to the repository, our users have normal ssh access. What I would like to do is log their user sessions so that I have an audit trail in the event that... (2 Replies)
Discussion started by: chrisb1609
2 Replies

6. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

7. Solaris

Graphical program no longer works after Solaris 10 upgrade

This is a fairly complex issue. I do not have a lot of knowledge on X11. But here are the things. I am running a program called Synergy off a Solaris server. The server sits in a remote network and can be accessed via NAT. Using Putty, I will enable X11 forwarding and launch Synergy via Putty.... (0 Replies)
Discussion started by: Leion
0 Replies

8. UNIX for Advanced & Expert Users

Max sessions a single user can've on Solaris server at the same time

There's a user that opens various login sessions with a particular SOLARIS server at the same time - this locks the server thats tried to get logged into.. Kindly help on how to know the max limit of sessions a particular user can open with a particular server at the same time. AND, how to... (2 Replies)
Discussion started by: its.simron
2 Replies

9. UNIX for Advanced & Expert Users

program running for one user and not for other user

i have an application that i can call from command line i can pass arguments to the command specifying the server name, user name and password. when i give my login information such as username and password in the argument, the command gets executd. as an fyi, i can login using ssh to... (2 Replies)
Discussion started by: bryan
2 Replies

10. UNIX for Dummies Questions & Answers

an hour less in 24 hour system

My program: __________________________________ #!/bin/ksh DAY=`date +%y%m%d` H=`date +%H` M=`date +%M` day=`date +%m/%d/%y` let h=$H-1 echo DAY $DAY echo H $H echo M $M echo day $day echo h $h _____________________________________ My result: (3 Replies)
Discussion started by: bobo
3 Replies
Login or Register to Ask a Question