Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kill -9 + disable messages (standard output) from kill command

Tags:

linux

ksh

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
  1. how to disable this message from the kill command?

  2. 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
like image 826
yael Avatar asked Dec 28 '22 13:12

yael


1 Answers

kill -9 $RESULT &> /dev/null

This will send stdout and stderr to /dev/null.

like image 89
tur1ng Avatar answered Feb 23 '23 16:02

tur1ng