A script to test MySQL port is running

83 记录 Leave a Comment
#!/bin/bash

ip="<MySQL HOST>"
port="<MySQL PORT>"
output_file="<Log File Path>"

while :
do
  nc -zv "$ip" "$port" > /dev/null

  datetime=$(date +"%Y-%m-%d %H:%M:%S")

  if [ $? -eq 0 ]; then
    echo "$datetime: Port $port is open on $ip" >> $output_file
  else
    echo "$datetime: Port $port is closed on $ip" >> $output_file
  fi

  sleep 10
done

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *