Reputation: 1073
#!/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?
Upvotes: 0
Views: 550
Reputation: 3090
There should be a space between "if and "[" like if [
. (Check line no 31)
To avoid such mistakes read man bash
Upvotes: 7