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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
10-09-2007, 01:52 PM
|
#1
|
|
LQ Newbie
Registered: Oct 2007
Posts: 2
Rep:
|
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.
|
|
|
|
10-09-2007, 04:45 PM
|
#2
|
|
Moderator
Registered: May 2001
Posts: 24,779
|
Can't you use "screen" to set up the session to the app? In that case on disconnection they can reconnect to their session?
|
|
|
|
10-09-2007, 07:48 PM
|
#3
|
|
Member
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202
Rep:
|
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.
|
|
|
|
10-10-2007, 06:29 AM
|
#4
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,938
|
ps -f|grep <username>
5th field is login time
|
|
|
|
10-10-2007, 07:39 AM
|
#5
|
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,211
Rep: 
|
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
|
|
|
|
10-10-2007, 08:37 AM
|
#6
|
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
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.
|
|
|
|
10-10-2007, 09:04 AM
|
#7
|
|
LQ Newbie
Registered: Oct 2007
Posts: 2
Original Poster
Rep:
|
Quote:
Originally Posted by bigearsbilly
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.
|
|
|
|
10-10-2007, 12:01 PM
|
#8
|
|
Senior Member
Registered: May 2005
Location: boston, usa
Distribution: fc-12/ fc-11-live-usb/ aix
Posts: 2,664
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:40 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|