bash - IF statement inside a loop in linux terminal not working -
currently trying execute bash file in crontab. however, command not working, command.
for ip in $(seq 3 80); ip2 in $(seq 9 254); count=$(ping -c 1 192.168.$ip.$ip2 | grep icmp* | wc -l) if [ $count -eq 0 ]; echo "host unreachable" else php /var/www/phpfile.php 192.168.$ip.$ip2 > 192.168.$ip.$ip2.txt; done; done the error console showing when execute command this:
if: command not found i checked spaces between brackets, tried remove them, none of solutions have worked. can please tell me wrong command? missing?
thank in advance.
you missing fi , ;, try this:
for ip in $(seq 3 80); ip2 in $(seq 9 254); count=$(ping -c 1 192.168.$ip.$ip2 | grep icmp* | wc -l); if [ $count -eq 0 ]; echo "host unreachable"; else php /var/www/phpfile.php 192.168.$ip.$ip2 > 192.168.$ip.$ip2.txt;fi; done; done it's better (for readability) break codes multiple lines insead of putting them in single line:
for ip in $(seq 3 80); ip2 in $(seq 9 254); count=$(ping -c 1 192.168.$ip.$ip2 | grep icmp* | wc -l) if [ $count -eq 0 ]; echo "host unreachable" else php /var/www/phpfile.php 192.168.$ip.$ip2 > 192.168.$ip.$ip2.txt; fi done done
Comments
Post a Comment