0

I want to set a cron job to periodically check what servers are active on our network. This will then update a MySQL db. When I run the script below I get error messages ERROR 1064 (42000), telling me I have an error in my SQL syntax. Where have I gone wrong with it?

#!/bin/bash

USER=username
PASS=password
HOST=localhost

for i in {100..250}
do
    count=$( nc -w2 192.168.178.$i 22 | grep SSH | wc -l )

    if [ $count -eq 0 ]
    then
        mysql -u$USER -p$PASS -h$HOST << EOF
        use tblServers;
        UPDATE tblServers SET online='no' WHERE ip='192.168.178.$i';
        EOF
    else
        mysql -u$USER -p$PASS -h$HOST << EOF
        use tblServers;
        UPDATE tblServers SET online='yes' WHERE ip='192.168.178.$i';
        EOF
    fi
done
user2165827
  • 153
  • 1
  • 3
  • 14

0 Answers0