I wrote the following script which enables timeout of 20 seconds if grep can not find the relevant string in the file.
The script works well, but the output from the script is like this:
./test: line 11: 30039: Killed
how to disable this message from the kill command?
how to tell kill command to ignore if process not exist?
THX
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