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

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
  • how to disconnect this message from the kill command?

  • how to tell kill to ignore if the process does not exist?

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
+3
source share
4 answers

kill -9 $RESULT &> /dev/null

It sends stdoutand stderrto / dev / null.

+3
source

you better watch the timeoutteam

man timeout

NAME
       timeout - run a command with a time limit

SYNOPSIS
       timeout [OPTION] NUMBER[SUFFIX] COMMAND [ARG]...
       timeout [OPTION]

DESCRIPTION
       Start  COMMAND,  and  kill  it if still running after NUMBER seconds.  SUFFIX may be `s' for
       seconds (the default), `m' for minutes, `h' for hours or `d' for days.
+2
source

, .

, , :

sh -c 'command_to_be_inettrupted&'

The idea is to infer a shell instance before the process begins. You may also need to β€œnohup” your team, but this was not necessary on my system.

For instance:

sh -c 'sleep 10&' ; sleep 1; killall sleep

This code will not produce any result, even though the first instance of sleep was killed.

+2
source

I think this post is related to job control. Try disabling it with set + m
if this does not work in ksh, try C #! / Bin / bash script

0
source

Source: https://habr.com/ru/post/1750644/


All Articles