lrsteelers
Programmer
Hello,
I am trying to develop a better script to kill users who have been idle for more than one hour.
The problem is that several users are allowed to have more than one session (this is a politcal reason) So, my script kills a users idle process and their active process. here is my script,(i have made it simplistic by havine one command per line, later I will condense and combine statments)
i have just added the sorts to help with the debuggin.
finger -i > times
grep hours times > times1
sort -d -f times1 > times2
cat /times2 | tr -s ''''|cut -f1 -d' ' > /times3
sort -d -f -u times3 > times4
for i in `cat /times4`
do
ps -ef |grep $i |grep -v root > lusers2
done
sort -d -f -u lusers2 > lusers3
cat lusers3 | cut -c 9-14,35-43 > lusers4
cat times2 | cut -c 31-37 > times5
cat lusers4 | while read number
do
kill -1 $number 3> luser5
done
else
exit
fi
file contents for times1
eight pts/10 Mon Nov 08 02:51 2 hour 29 minutes
tens pts/5 Mon Nov 08 01:35 9 hours 15 minutes
quality pts/28 Mon Nov 08 4:51 6 hours 18 minutes
quality pts/29 Mon Nov 08 04:51 6 hours 18 minutes
artr pts/139 Mon Nov 08 05:38 1 hour 29 minutes
file contents for times3
eight
tens
quality
artr
file contens for luser3
artr 75200 118180 0 08:41:32 pts/139 0:00
artr 89618 91344 0 08:04:13 pts/104 0:00
eights 42720 23208 0 02:51:54 pts/10 0:02
tens 37106 37844 0 01:35:24 pts/5 0:04
tens 42317 4590 0 01:35:24 pts/20 0:04
quality 21324 23676 0 04:51:59 pts/29 0:00
quality 22732 46066 0 04:51:36 pts/28 0:00 -ksh
lusers4
75200 pts/139
89618 pts/104
42720 pts/10
37106 pts/5
42314 pts/20
21324 pts/29
22732 pts/28
file contents for times5
pts/10
pts/5
pts/139
pst/29
pts/28
Altough the user artr has two sessions, only one is idle,
I do not want to kill both of these session, just the idleone
I thought that i could do a compare of the pts commands
in the finger command to the psg commands
I would like to have the file "lusers4" to check for the pts/xx in file times5
could you please help me develop a better kill script to
kill only the idle process for each users?
Thank you for your time.
LRSTEELERS
black and gold forever
I am trying to develop a better script to kill users who have been idle for more than one hour.
The problem is that several users are allowed to have more than one session (this is a politcal reason) So, my script kills a users idle process and their active process. here is my script,(i have made it simplistic by havine one command per line, later I will condense and combine statments)
i have just added the sorts to help with the debuggin.
finger -i > times
grep hours times > times1
sort -d -f times1 > times2
cat /times2 | tr -s ''''|cut -f1 -d' ' > /times3
sort -d -f -u times3 > times4
for i in `cat /times4`
do
ps -ef |grep $i |grep -v root > lusers2
done
sort -d -f -u lusers2 > lusers3
cat lusers3 | cut -c 9-14,35-43 > lusers4
cat times2 | cut -c 31-37 > times5
cat lusers4 | while read number
do
kill -1 $number 3> luser5
done
else
exit
fi
file contents for times1
eight pts/10 Mon Nov 08 02:51 2 hour 29 minutes
tens pts/5 Mon Nov 08 01:35 9 hours 15 minutes
quality pts/28 Mon Nov 08 4:51 6 hours 18 minutes
quality pts/29 Mon Nov 08 04:51 6 hours 18 minutes
artr pts/139 Mon Nov 08 05:38 1 hour 29 minutes
file contents for times3
eight
tens
quality
artr
file contens for luser3
artr 75200 118180 0 08:41:32 pts/139 0:00
artr 89618 91344 0 08:04:13 pts/104 0:00
eights 42720 23208 0 02:51:54 pts/10 0:02
tens 37106 37844 0 01:35:24 pts/5 0:04
tens 42317 4590 0 01:35:24 pts/20 0:04
quality 21324 23676 0 04:51:59 pts/29 0:00
quality 22732 46066 0 04:51:36 pts/28 0:00 -ksh
lusers4
75200 pts/139
89618 pts/104
42720 pts/10
37106 pts/5
42314 pts/20
21324 pts/29
22732 pts/28
file contents for times5
pts/10
pts/5
pts/139
pst/29
pts/28
Altough the user artr has two sessions, only one is idle,
I do not want to kill both of these session, just the idleone
I thought that i could do a compare of the pts commands
in the finger command to the psg commands
I would like to have the file "lusers4" to check for the pts/xx in file times5
could you please help me develop a better kill script to
kill only the idle process for each users?
Thank you for your time.
LRSTEELERS
black and gold forever