#!/bin/sh
who
echo "\r"
echo Enter the terminal ID of the user in use:
echo "\r"
read TERM_ID
echo "\r"
ps -t $TERM_ID | grep sh
echo "\r"
echo Enter the process number to end:
echo "\r"
read PID
echo "\r"
kill -9 $PID
What this code does is ultimately grab the PID of a users sh and kill it. Sometimes users accidentally close their terminal windows the wrong way and our UNIX logon script does not let them back into the system because it still sees them logged in.
What I would like to do is take this script a step further and have it auto kill the process by finding the PID after the grep sh and sticking that into the kill string.
maybe:
who
echo "\r"
echo 'Enter the terminal ID of the user in use: '
echo "\r"
read TERM_ID
ps -t $TERM_ID | grep sh | read PID junk
kill -9 $PID
that's a no go it is not pulling the PID #
ps -t $TERM | grep sh | awk '{print $1}'
sould give you the PID. Assign it in a variable or just let your SHELL evaluate it on a direct KILL command.
Kill -9 ` command`
Are you using a customized login? Why isn't the login system not allowing again? This might apply a restriction of just one tty per user login. May be I didnot understand the problem correctly.
grep'ing can be done in awk itself
ps -t $TERM | awk '/sh/ { print $1 }'
#!/bin/sh
who
echo "\r"
echo Enter the terminal ID of the user in use:
echo "\r"
read TERM_ID
echo "\r"
ps -t $TERM | awk '/sh/ { print $1 }'
read PID
echo "\r"
kill -9 $PID
works great unless 2 PID's are returned. I guess it is typing:
kill -9 0001
0002
instead of kill -9 0001 0002
how do I get it to read the PID's and put them all into 1 line?