Alright, so I'm running this on an Ubuntu machine that's hosting my Nagios service. This script uses FreeTDS to connect to our MSSQL database, and then it should execute a query, trim the results, and finally pass it to an if/else statement so Nagios can make sense of it. The problem I'm running into is when I try to run the script, nothing happens. I hit enter and the terminal moves down a line, never returns anything, and just sits there indefinitely until I hit Ctrl+C. I've copied the script below. I'd really appreciate it if someone could lend a hand. Thanks!
#!usr/bin/perl use strict; my($tsql, $origresult, $result, $args); $args = "-H production -U UsernameRemoved -P PasswordRemoved -p 1433 - +I InstanceRemoved"; $tsql = `tsql $args`; $origresult = `/usr/bin/printf "%b" "select SUM(ocount) TotalCounts fr +om (\n select dbd.DateStart, count(oo.id_orders) As oCount, DATEPART( +dw, dbd.datestart) as DayNumber\n from [dbo].[DaysBetweenDates](dbo.BeginningOfDay(CURRENT_TIMES +TAMP), dbo.endofday(CURRENT_TIMESTAMP)) dbd\n left join orders oo on dbd.DateStart = oo.orderdate\n and oo.OrderPlacedBypk = '011CA1AF-0C20-4B87-93CC-11886C530E2D +'\n group by dbd.DateStart\n ) As Total\n where DayNumber not in (6,7)\n GO"`; $result = substr($origresult, 12, 2); if ("$result" >= 20 ){ print "OK - Order count is at or above average.\n"; exit 0; #Nagios OK exit code } elsif ("$result" <= 7) { print "CRITICAL - Order count is below average.\n Current Aver +age = $result"; exit 2; #Nagios CRITICAL exit code } else { print "UNKNOWN - Unable to determine order average.\n Variable +s are:"; exit 3; #Nagios UNKNOWN exit code }
In reply to Trying to connect to MSSQL and return result. Script hangs indefinitely. by Logic_Bomb421
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |