1

Need an advise on how to create an automate script to check connectivity from multiple servers to one server (DB) within Windows server environment either with telnet/portqry and also the script will create a .txt file for unsuccessful connection

Thanks in advance for your help Claudia

npocmaka
  • 55,367
  • 18
  • 148
  • 187

3 Answers3

0

Why don't you just ping it?

if ping -q -c 1 yourserver; then
    echo 'server is online'
else
    echo 'server is offline'
fi

I think this question is similar.

This is bash because you have used bash tag

If you need to check specific port, then you can use this code:

timeout 10 "telnet server port"
if [[ $? == 124 ]]; then # timeout is going to exit with 124 code if it timeouts because of the telnet
    echo 'server is online'
else
    echo 'server is offline'
fi
Community
  • 1
  • 1
Aleks-Daniel Jakimenko-A.
  • 10,335
  • 3
  • 41
  • 39
0

Take a look at IPSentry. We've been using it for a number of years in a mixed Windows/UNIX/Linux environment and found it works well.

Al Maki
  • 123
  • 5
0

Since you claim in the comments that you are really trying to test connectivity into a Sql Server, why not use .Net SqlConnection class? Like so,

$server = "server\instance"
$conStr = "Data Source=$server;Integrated Security=true;Initial Catalog=master;Connect Timeout=3;"
$sqlConn = new-object ("Data.SqlClient.SqlConnection") $conStr
try {
    $sqlConn.Open()
    if ($sqlConn.State -eq 'Open') {
        $sqlConn.Close();
        write-host "$server is alive."
    } else {
        write-host "$server connection problem: $($sqlConn.State.ToString())"
    }
} catch {
    write-host "$server is unavailable:"
}
vonPryz
  • 22,996
  • 7
  • 54
  • 65