LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-09-2007, 02:52 PM   #1
scrizo
LQ Newbie
 
Registered: Oct 2007
Posts: 2

Rep: Reputation: 0
Writing a script to kill users logged in twice


I'd like to know the best approach at writing a script that will kill users who are logged in twice.

We use linux for our business and the users dont get access to a shell instead they login and go straight to the program. However if for some unforseen instance they lose connection, when they login and go to the program they cant update anything because the process is in use. Is there a way to kill the double logged users more likely by timestamp so I know 8:00 logged in once and 12:00pm i know to kill the 8:00 one because thats the first one. Man I hope I didnt confuse anyone with my question.
 
Old 10-09-2007, 05:45 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,688
Blog Entries: 54

Rep: Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955
Can't you use "screen" to set up the session to the app? In that case on disconnection they can reconnect to their session?
 
Old 10-09-2007, 08:48 PM   #3
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Rep: Reputation: 31
You might want to consider to examine the output of 'ps' command. For example if you do:
> ps -Af | grep "pts\/"
You might see 'double' users. I'm sure that there is an option in 'ps' to see start time of the process.
 
Old 10-10-2007, 07:29 AM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
ps -f|grep <username>
5th field is login time
 
Old 10-10-2007, 08:39 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,314

Rep: Reputation: 175Reputation: 175
sounds harsh, I'd avoid it logging things off summarily like that.

how do they log in? can you not use exec to run the program?
or put the program as the shell in the passwd file?

or kill all users at midnight?

Last edited by bigearsbilly; 10-10-2007 at 08:39 AM. Reason: better ideas
 
Old 10-10-2007, 09:37 AM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
There are also the w and who commands.

You should probably only kill login shells with a long idle time. And you should be prepared to get a lot of hate mail from your users.
 
Old 10-10-2007, 10:04 AM   #7
scrizo
LQ Newbie
 
Registered: Oct 2007
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bigearsbilly View Post
sounds harsh, I'd avoid it logging things off summarily like that.

how do they log in? can you not use exec to run the program?
or put the program as the shell in the passwd file?

or kill all users at midnight?
In the passwd file is the program as there shell. I need to kill them because when they get disconnected or are logged out and get back in the application they cannot do any updates because the pid is locked to there session still preventing them from making updates and then I have to manually kill the pid of the users so they can get back in the account.
 
Old 10-10-2007, 01:01 PM   #8
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,197

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
hi, here is my quick-and-dirty solution.
this works in aix - not sure what all the ps options do:
Code:
# use who to determine who is logged on more than once:
dupe=`who | awk '{print $1}' | sort | uniq -d`

for item in `echo $dupe`
do
 echo dupe = $item
 kill -9 `ps -ANaedfklm | grep $item | grep ksh | grep -v grep | head -n 1 | awk '{print $4}'`
done
you would need to cron this every minute or every day...
my experirience is that ps displays the most recent login on top so you may need to use tail instead of head.
you may need to substitute 'ksh' with whatever program they are running at login.

Last edited by schneidz; 10-10-2007 at 01:17 PM.
 
  


Reply

Tags
bash, linux, parser, scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
4 of the same users logged on... true_atlantis Linux - Newbie 1 04-14-2006 12:54 AM
Linux HA and writing scripts to kill process sceadu Programming 0 07-28-2005 04:27 AM
users who logged before czezz Solaris / OpenSolaris 1 11-24-2004 07:12 AM
No Users logged in X kaise_sose Linux - Software 2 10-19-2004 03:57 AM
writing a script to perform a function on each users mail folder jhill Linux - Newbie 2 08-24-2004 08:18 AM


All times are GMT -5. The time now is 12:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration