kill: 5656 :参数必须是进程或作业 ID

kill: 5656 :参数必须是进程或作业 ID

redis-server开启(已启动redis-server &)。

在终端中运行此命令非常有效:

kill -s SIGTERM "`pgrep redis-server`"

但是在脚本中它会输出以下消息并且不会终止该进程:

myscript.sh: line 17: kill: 1448
1452: arguments must be process or job IDs

(如果我这样做:pgrep redis-server在这个例子中它将输出我1448

我的完整源脚本:

#!/bin/bash

if [ -a "redis-server_must_be_ON" ]
then
  if [ "`redis-cli PING`" != "PONG" ]
  then
    redis-server &
    if [ "`redis-cli PING`" != "PONG" ]
    then
      echo "redis-server still not running while it should have been set on." >> /dev/stderr
      exit 1
    fi
  fi
else
  if [ "`redis-cli PING`" == "PONG" ]
  then
    kill -s SIGTERM "`pgrep redis-server`"
    if [ "`redis-cli PING`" == "PONG" ]
    then
      echo "redis-server still running while it should have been set off." >> /dev/stderr
      exit 1
    fi
  fi
fi

(这里如果我pgrep redis-server用某种睫毛膏代替,pgrep bash1.sh效果也很好)。

我的脚本正确吗?我遗漏了什么?

相关内容