INT 21h

Hi, I am Vladimir Smagin, SysAdmin and Kaptain. Telegram Email / GIT / Микроблог / Thingiverse / RSS / GPG

bash: wait database for connection

№ 10430 В разделе "Sysadmin" от December 6th, 2019,
В подшивках: , ,

You can easily use it to check MySQL or Postgresql connection.

#!/bin/bash

for i in `seq 1 ${CONNECT_TIMEOUT}`;
do
  mysql -h "${DB_HOST}" -u${DB_USERNAME} -p${DB_PASSWORD} ${DB_DATABASE} -e 'select 1'
  if [ $? -eq 0 ]; then
    echo "Connected to MySQL"
    exit 0
  fi
  if [ $i -eq ${CONNECT_TIMEOUT} ]; then
    echo "MySQL timeout"
    exit 1
  fi
  sleep 1
done

Нет комментариев »

Leave a Reply

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

*

Яндекс.Метрика

Fortune cookie: "Let no more gods or exploiters be served. Let us learn rather to love one another." [Francisco Ferrer]