-1

I have the following simple bash script. for some reason it always returns true.

#!/bin/bash
service=hhvm
status=($(ps -ef | grep -v grep | grep $service | wc -l))
if [[ $status -eq 0 ]]; then
    echo "starting $service"
    service hhvm start
else
    echo "$service running"
fi
1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Mitch
    Jan 14, 2015 at 19:18

2 Answers 2

2

Final script that worked. in chat

#!/bin/bash
service=hhvm
if ! (($(ps -ef | grep -v "grep"| grep "$service" | wc -l))) ; then
    echo "starting $service"
    service hhvm start
else
    echo "$service is running"
fi
2
  • 1
    Thanks again for taking the time to help me. I owe ya 1.. or 2 lol. Have a good day. :-]
    – r3wt
    Jan 14, 2015 at 16:55
  • I'm not sure why, but it stopped working again. weird. maybe by dev box got hacked, who knows
    – r3wt
    Jan 15, 2015 at 13:14
2
foo=3
if [[ $foo -eq 0 ]]; then     # -eq: equal
  echo "foo equals 0"
else
  echo "foo is not equal to 0"
fi
8
  • still returns true...
    – r3wt
    Jan 14, 2015 at 14:32
  • You might want to add a small explanation Jan 14, 2015 at 14:33
  • @r3wt I get: foo is not equal to 0, just like @KasiyA 's suggestion Jan 14, 2015 at 14:36
  • @Jacob it always returns "foo equals 0"
    – r3wt
    Jan 14, 2015 at 14:36
  • 1
    @r3wt: Sorry, your bash is broken.
    – Cyrus
    Jan 14, 2015 at 14:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .