How to write a shell script to check db connection

Discussion in 'Programming/Scripts' started by user343, Aug 18, 2020.

  1. user343

    user343 New Member

    I have this command to connect the DB.
    ./ssgodbc.linux64 -d "dsn" -u "username" -p 'pswd' -v
    How can I write a shell script to generate a mail alert if there is no db connection.
  2. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    Examine the return value of that command. Experiment what the value is when it does connect to database, and when it does not.
    For example something like this
    set -x
    ./ssgodbc.linux64 -d "dsn" -u "username" -p 'pswd' -v
    echo $?;
    Then make a conditional statement that sends e-mail if value indicates command failed.

Share This Page