I wrote the following script that allows a timeout of 20 seconds if grep cannot find the corresponding line in the file.
The script works well, but the output from the script looks like this:
./test: line 11: 30039: Killed
thanks
Yael
#!/bin/ksh
( sleep 20 ; [[ ! -z ` ps -ef | grep "qsRw -m1" | awk '{print $2}' ` ]] && kill -9 2>/dev/null ` ps -ef | grep "qsRw -m1" | awk '{print $2}' ` ; sleep 1 ) &
RESULT=$!
print "the proccess:"$RESULT
grep -qsRw -m1 "monitohhhhhhhr" /var
if [[ $? -ne 0 ]]
then
print "kill "$RESULT
kill -9 $RESULT
fi
print "ENDED"
./test
the proccess:30038
./test: line 11: 30039: Killed
kill 3003
source
share