Kill: 5656: Arguments Must Be Process or Job Ids
Having Redis-Server on (Launched with Redis-Server &). Running This Command in a Terminal Works Perfectly: Kill -S Sigterm "`Pgrep Redis-Server`" but in a...
Having redis-server ON (launched with redis-server &).
Running this command in a terminal works perfectly:
kill -s SIGTERM "`pgrep redis-server`"
But in a script it outputs the following message and does not kill the process:
myscript.sh: line 17: kill: 1448
1452: arguments must be process or job IDs
(if I do: pgrep redis-server in this example it will outputs me 1448)
My complete source script:
#!/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
(Here if I replace the pgrep redis-server with some sort of mascarade like pgrep bash1.sh it also works fine).
Is my script correct, what do I miss ?