0

I'm new to Shell scripting and I have created the below to run a script and get the output and print a msg based on the output.

#!/bin/bash
OUTPUT=$(sh ./myprocess.sh | tail -1)
echo $OUTPUT
if [[$OUTPUT == *"\"process\":\"ACTIVE\""* ]]; then
echo "Process Active"
else
echo "Process Down"
fi

The echo prints the output but my script fails saying "command not found a line 4"

Jeeppp
  • 1,323
  • 2
  • 11
  • 27
  • 1
    http://shellcheck.net/ will identify this for you. It's generally appreciated if you fix everything that finds **before** asking questions here. – Charles Duffy Aug 02 '17 at 20:08
  • 1
    BTW, `sh ./myprocess.sh` is generally bad practice -- it means you're ignoring `#!/bin/bash` (if that processes starts with it) and forcing the shell that interprets it to be `/bin/sh` (which supports a smaller array of syntax). – Charles Duffy Aug 02 '17 at 20:10
  • You also might consider using lowercase names for your own variables -- see fourth paragraph of the relevant spec at http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html, indicating that all-caps names are used by the OS and that applications are guaranteed to avoid conflicting with POSIX-defined tools if they use names containing lower-case characters for their own variables. – Charles Duffy Aug 02 '17 at 20:11
  • @CharlesDuffy I agree on you mentioning on the way to call the process. Is there a better way to do that? – Jeeppp Aug 02 '17 at 20:40
  • If it's executable, just `./myprocess.sh` (and if it's not executable, I'd suggest fixing the permissions so it is). – Charles Duffy Aug 02 '17 at 20:41

0 Answers0