ProgrammingThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.