kill crashed out users

Hi all,

We have a problem where we get a fair few users either exiting incorrectly or crashing. I'm trying to get a script together that runs every hour to kill these processes off.

We are running Sco OperServer(TM) Release 5

The command we use to get a list of users who have crashed:
ps -ef | grep " 1" | grep "\-sh"
# ps -ef | grep " 1" | grep "\-sh" | cut -c10-15
root 2945 1 0 07:45:38 tty05 00:00:00 -sh
ben 7259 1 11 09:07:14 ttyp68 00:00:00 -sh
bill 8059 1 11 09:16:15 ttyp71 00:00:00 -sh
bob 8553 1 11 09:30:15 ttyp3 00:00:00 -sh

Obviouly to get the pid:
# ps -ef | grep " 1" | grep "\-sh" | cut -c10-15
2945
4184
5829
7259
8059
8553

The problem I have is the PID can be 4 or 5 numbers. Hence when the PID has 4 numbers their is a space before and cannot use kill $i in a for loop. Is their a better way of doing this or is their a way of stripping the space if their is one??

Thank

Use awk to print out column 2 in stead of bitwise cut.

ps -fe | grep "1" | grep "\-sh" | awk '{print $2}'

will do the trick. You can also use the output from that statement in xargs to eliminate the loop you are referring by

ps -fe | grep "1" | grep "\-sh" | awk '{print $2}' | xargs kill -9

Thanks that works fine :slight_smile: