|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Script to prevent multiple logons
Scenario
User logs in at Workstation 1 User then tries to logon at Workstation 2 while still logged in at Workstation 1. What I am looking for is a script which will test if a user is already logged on elsewhere, and if so, display a message saying "Already logged on at <Station Name>" and then terminate the current logon. Guy Thomas
__________________
Guy Thomas Ezine http://computerperformance.co.uk/ezine/newsletter_subs.htm |
|
#2
|
|||
|
|||
|
guythomas
You can achive it by adding the following in .bashrc file present in the user's home directory This is for a particular user. Code:
tt=`whoami`
tt=`who | grep $tt | wc -l`
if [ $tt -gt 1 ]
then
echo Already logged on. Please press Enter to exit.
read
exit
fi
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
unset tt
FYI The code Code:
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
would be already in .bashrc file. Here you have some problem. Some times ( seldom ) the who command will display as if the user has logged in even if they were not logged in. This happens ( this too very rarely ) when the user terminal abruptly terminates. So it not advisible to set this for a root user. Last edited by murugesan : April 15th, 2004 at 11:51 PM. |
|
#3
|
|||
|
|||
|
A slight modification in the script
Code:
stty erase '^C'
stty intr ''
tt=`whoami`
tt=`who | grep $tt | wc -l`
if [ $tt -gt 1 ]
then
echo Already logged on. Please press Enter to exit.
read
exit
fi
stty intr '^C'
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
unset tt
The previous code will allow the user to login when Ctrl C is pressed instead of Enter while loggin in. Regards, Murugesan |
![]() |
| Viewing: Dev Shed Forums > Web Site Management > Scripts > Script to prevent multiple logons |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|