Operating System - HP-UX
1829124 Members
2054 Online
109986 Solutions
New Discussion

fuser -ku /dev/pts/0 command does not wok

 
ChrisCiti
Occasional Advisor

fuser -ku /dev/pts/0 command does not wok

Hi,
I have a cron job that will kill users that are active for 24 hours. My cron job contains fuser -ku "/dev/pts/0". I noticed that after the cron has ran, the user with pts/0 is still present in "who" command. when I manually ran the script, the user is killed. Is it normal for fuser -ku command to work only after 2nd and 3rd execution?
regards,
chris
8 REPLIES 8
Peter Godron
Honored Contributor

Re: fuser -ku /dev/pts/0 command does not wok

Chris,
the fuser -k sends a kill -9 level, which terminates the process without caring about the niceities, such as cleaning up the utmp and wtmp files.

This is were this problem can arise from.

Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.

So far you have never awarded any points !
SANTOSH S. MHASKAR
Trusted Contributor

Re: fuser -ku /dev/pts/0 command does not wok

Hi Chris,

I also have similar script working for last
6 years.

Sometime at command line

fuser -ku

won't kill if login is "old".

Pl. give details of ur script.

-Santosh
ChrisCiti
Occasional Advisor

Re: fuser -ku /dev/pts/0 command does not wok

Hi Peter,
thanks for providing the procedure on how to award points. :)
But is it ok to re-run the fuser -ku /dev/pts/0 until its killed? 2 to 3 times?
regards,
chris
ChrisCiti
Occasional Advisor

Re: fuser -ku /dev/pts/0 command does not wok

Hi Mhaskar,
My script will grep for users with "rp" and redirected to a /tmp/file. Then it will check for the login time. If the login time is equal to a specific value that translates to 24 hours, the /pts/0 (for ex.) will be killed using the fuser -ku "/dev/pts/0". This script will be run using cron twice daily. Sometimes the user was killed sometimes its not.
regards,
chris
SANTOSH S. MHASKAR
Trusted Contributor

Re: fuser -ku /dev/pts/0 command does not wok

Hi Chris,

Have u tested the script, i.e. login to
a terminal and keep it idle for some time
set in ur script values for this test session
and run script manually,
insert set -vx at the beginning of ur script
this will show debugging info. of ur script.
Go through script attached herewith which
I use to run since last 6 years without
any problem. Which Warns and then kills the
terminals.

Regards.

-Santosh
SANTOSH S. MHASKAR
Trusted Contributor

Re: fuser -ku /dev/pts/0 command does not wok

I think there is problem in attachment.
Againing uploading it.
SANTOSH S. MHASKAR
Trusted Contributor

Re: fuser -ku /dev/pts/0 command does not wok

same problem,

Copying here the contents.


--------------------------------
## Extracts logged-in terminals .

for Term in `who -u|cut -c 12-20`
do

## To get idle time of given terminal .

Idle=`who -u|grep $Term|cut -c 41-42`

## To get login name of given terminal .

Log=`who -u|grep $Term|cut -c 1-10`

## To get LTS of given terminal .

lts=`who -u|grep $Term|cut -c 15`

## If login is not csms or mtnlbckp or LTS is not P and idle time is
## more than 10 minutes then sends warning message to that terminal .

if [ \( $Idle -gt 10 -a $Idle -le 25 \) -a ! \( $Log = csms -o $Log = ccbs -o $Log = oracle -o $lts = p -o $Term = console -o $Term = ttytf -o $Term = ttyt6 -o $Term = ttys3 -o $Term = ttyv5 -o $Term = ttyvc \) ]
then
alm=1

## Sends Audible Alarm to idle terminal .

while [ $alm -lt 5 ]
do
echo "\a\c" > /dev/$Term ## Sends Alarm
sleep 1
alm=`expr $alm + 1`
done

## Sends message to idle terminal .

echo "\n\t\t\t`date`" >/dev/$Term
echo "\n\t\033[5mYou are not using the system for last $Idle minutes , press \n\tand start using it or Logout immediately !!!\033[0m\n" > /dev/$Term



## Saves details to logfile idle.log .

echo "\n`date`\nUser $Log at $Term is idle for $Idle minutes !">> /Mi_cron/cron_log/Idle.log

fi



## Terminates the terminal if it is idle more than specified time after
## warning .


if [ $Idle -gt 25 -a ! \( $Log = csms -o $Log = ccbs -o $Log = oracle -o $lts = p -o $Term = console -o $Term = ttytf -o $Term = ttyt6 -o $Term = ttys3 -o $Term = ttyv5 -o $Term = ttyvc \) ]
then

## Terminates the terminal .

/usr/sbin/fuser -ku /dev/$Term > /Mi_cron/cron_log/Process.log


## Saves details in logfile kill.log .

echo "\n`date`\nUser $Log at $Term idle for $Idle minutes, terminated !">> /Mi_cron/cron_log/Kill.log

fi



done
--------------------------------------------
ChrisCiti
Occasional Advisor

Re: fuser -ku /dev/pts/0 command does not wok

Hi ,
Thanks for the sample script. My script is actually running fine. I think the problem is with the fuser command. Sometimes the user is get killed on the first run of the script sometimes on the second run.
regards,
chris