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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.