我编写了以下脚本,如果grep无法在文件中找到相关的字符串,则启用超时20秒.
该脚本运行良好,但脚本的输出如下:
./test: line 11: 30039: Killed
>如何从kill命令禁用此消息?
>如果进程不存在,如何告诉kill命令忽略?
谢谢
耶尔
#!/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
解决方法:
kill -9 $RESULT&>的/ dev / null的
这会将stdout和stderr发送到/ dev / null.