Question

I have a very basic script that keeps spitting back that the commands are not found. Ive looked all over this site and can not find an answer that works for me. The path to bash is correct. Ive checked the script with od. Ive run dos2unix. None of this helps me.

SCRIPT:

    #!/bin/bash
    HYBRISPROC=`ps -eo pid,command | grep [h]ybris | grep -v grep | awk '{print $1}'`
    echo "Looking for Hybris..."
    echo $HYBRISPROC

RESULTS:

    ./HybrisStopStart.sh: line 5: ps: command not found
    ./HybrisStopStart.sh: line 5: grep: command not found
    ./HybrisStopStart.sh: line 5: awk: command not found
    ./HybrisStopStart.sh: line 5: grep: command not found
    Looking for Hybris...

Any ideas? If I run the command just on its own it works fine. Ive tried it as sudo as well and et the same results.

TIA

Was it helpful?

Solution

How about it?

#!/bin/bash
HYBRISPROC=`ps -eo pid,command | grep [h]ybris | grep -v grep | awk '{print $1}'`
echo "Looking for Hybris..."
echo "$HYBRISPROC"

(OR)

#!/bin/bash
HYBRISPROC="ps -eo pid,command | grep [h]ybris | grep -v grep | awk '{print $1}'"
echo "Looking for Hybris..."
bash -c "$HYBRISPROC"

(OR)

#!/bin/bash
HYBRISPROC="ps -eo pid,command | grep [h]ybris | grep -v grep | awk '{print $1}'"
echo "Looking for Hybris..."
eval "$HYBRISPROC"

TOTALY:

you can see the difference:

#!/bin/bash
LS=`ls -l`
echo $LS    #nasty way
echo 
echo "$LS"  #good way

OTHER TIPS

Try to add

PATH="$PATH:/usr/bin:/bin"

before code. Looks like bin directory is not on your path. So the commands are not found.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top