0
#!/bin/bash
value=$(</var/www/sym_monitor/man_mon.txt)
value2=$(</var/www/sym_monitor/panel_mon.txt)

pro=$(ps -ef |grep sym |grep -v grep |awk '{ print $2 }')
echo "$pro";
echo "STARTED";

if [ "$value" == "false" ]; then


 cd /var/www/symmetric-ds-3.1.6/bin;
sleep 30;
(sudo ./sym --port 8082 --server);
 #(sudo /bin/bash /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server);

echo "IF";


else 
if [ "$value2" == "false" ]; then


 cd /var/www/symmetric-ds-3.1.6/bin;
sleep 30;
(sudo ./sym --port 8082 --server);
 #(sudo /bin/bash /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server);
echo "ELSEIF";

else
if[ "$pro" == "" ]; then

echo "pro";
 cd /var/www/symmetric-ds-3.1.6/bin;
sleep 30;
(sudo ./sym --port 8082 --server);
fi
fi
fi


echo "END";

In the above script in the last else if is giving syntax error. Any Idea? In the variable $pro even though no such process running some process Id's are printing? why?

Before that script looks like below and worked absolutely fine.

#!/bin/bash
    value=$(</var/www/sym_monitor/man_mon.txt)
    value2=$(</var/www/sym_monitor/panel_mon.txt)

 if [ "$value" == "false" ]; then

     cd /var/www/symmetric-ds-3.1.6/bin;
    sleep 30;
    (sudo ./sym --port 8082 --server);
     #(sudo /bin/bash /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server);


    elif [ "$value2" == "false" ]; then

     cd /var/www/symmetric-ds-3.1.6/bin;
    sleep 30;
    (sudo ./sym --port 8082 --server);
     #(sudo /bin/bash /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server);

    fi

This is the first version of script which worked absolutely fine. But I have to add one more condition to it which is if no process running as mentioned in the first script above then the code in the condition should run. I don't know why even though there is no process running it is giving some numbers into $pro value. any idea?

2
  • try to correct the indent. its likely that you'll find the error while doing this.
    – hek2mgl
    Commented Feb 28, 2013 at 5:11
  • Some style corrections besides the actual error: don't use ; at the end of lines in shell scripts, and use elif instead of else if (and also remove the extra fis). Also, is there any reason you're running your sudo commands in subshells (with parentheses)? Commented Feb 28, 2013 at 6:14

1 Answer 1

7

There should be a space between "if and "[" like if [. (Check line no 31)
To avoid such mistakes read man bash

Not the answer you're looking for? Browse other questions tagged or ask your own question.