LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 01: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, 04:45 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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, 07: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, 06:29 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
ps -f|grep <username>
5th field is login time
 
Old 10-10-2007, 07:39 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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 07:39 AM. Reason: better ideas
 
Old 10-10-2007, 08:37 AM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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, 09: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, 12:01 PM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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 12:17 PM.
 
  


Reply

Tags
bash, linux, parser, scripting



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-13-2006 11:54 PM
Linux HA and writing scripts to kill process sceadu Programming 0 07-28-2005 03:27 AM
users who logged before czezz Solaris / OpenSolaris 1 11-24-2004 06:12 AM
No Users logged in X kaise_sose Linux - Software 2 10-19-2004 02:57 AM
writing a script to perform a function on each users mail folder jhill Linux - Newbie 2 08-24-2004 07:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:28 AM.

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
Open Source Consulting | Domain Registration