I tried below command to store output to variable :
k=$(kill -HUP 1234) #command getting executed but not storing to variable
echo "$k"
For checking if the output contains the word, i can do like this :
if [[ outputvar =~ .*No such process*. ]]
As per the examples, above should work , but i donno why its not working . Can you tell me correct way so that if I cannot restart the process, I can atleast start a new process with direct gunicorn_django command
Usually such error messages are output on the
stderrstream, while the$()construct returns only thestdoutstream. You need to redirectstderrtostdout:Your regular expression has an error: the
*.at the end must be.*; you will also need to quote your strings in your test:Note that
"$k"is quoted, while the spaces in the regular expression are escaped; you cannot quote the regular expression (as".*No such process.*"), as using a quoted string in a=~test forces string match instead of a regular expression match.