[Nagiosplug-help] Strange problem with Bash, AWK and check_http

Edward Blum eddy.blum at gmail.com
Sun Apr 15 23:59:10 CEST 2012


Super useful info Alex!  Many thanks for taking time to reply, much
appreciated! Script now working nicely :) I tried to use trim but couldn't
get anything useful out of it, and think I searched google for help for
hours and hours but couldn't find much. I'll get the hang of it all one
day. Just needed the directions of an old hat!

P.S Nagios rocks!

Cheers


On 11 April 2012 17:16, Alex Griffin <agriffin at nagios.com> wrote:

> Hey Edward,
>
> I'm glad you got everything figured out! I just thought I'd leave some
> shell tips based on the few lines of your script that you posted.
>
> Your first pipeline can be replaced by a single awk command without losing
> much clarity (well, if you know awk). You also had some unnecessary quotes
> in your 'command' variable assignment.
>
>    test=$(awk -F= '/ServerFileName/ && /HHR/ {print $2}' /tmp/updates.txt)
>
>    command="$check_http -v -N -H update.efefktdfde.co.uk -u/$test"
>
> If you don't know a whole lot about awk, or if it's confusing for some
> other reason, you can at least get rid of cat by moving the filename to
> grep's invocation.
>
>    grep ServerFileName /tmp/updates.txt
>
> Finally, removing nasty invisible characters is a job for the tr utility.
>
>    fileName=$(echo "$fileName" | tr -dc [:print:])
>
> Alex Griffin
> ---
> Tech Team
> agriffin at nagios.com
>
>
> On 04/11/2012 10:20 AM, Edward Blum wrote:
>
>> FIXED!
>>
>> With a little research and when running check_http with -v I see the line
>>
>>  is 135 charactersktrace.co.uk:80/**SetupHHRImporter1020.exe<http://charactersktrace.co.uk:80/SetupHHRImporter1020.exe>
>> <http://charactersktrace.co.**uk:80/SetupHHRImporter1020.exe<http://charactersktrace.co.uk:80/SetupHHRImporter1020.exe>
>> **>
>>
>>
>> For some reason the variable had a funny hidden character of some sort
>> in which check_http doesn't like.
>>
>> I cleansed the variable with:
>>
>>
>> fileName=$(echo $fileName | egrep "[a-z,A-Z,.,0-9]{1,}" -o)
>>
>>
>>
>> On 10 April 2012 23:01, Edward Blum <eddy.blum at gmail.com
>> <mailto:eddy.blum at gmail.com>> wrote:
>>
>>    Hi There,
>>
>>    I am having very strange problems creating a nagios plugin in Bash
>>    using check_http to check contents of a Amazon S3 Bucket.
>>
>>    I am grabbing the URL of the file to grab from a txt file (changes
>>    often) inside the bucket and using awk and grep extracting the
>> Filename.
>>
>>    I have using the following syntax:
>>
>>    check_http -H myhost.com <http://myhost.com/> -N -v -u /testing.exe
>>
>>
>>    Now this works fine when I run from the command line it also works
>>    fine when running from the bash script. The problem lies when I try
>>    the use the variable extracted using awk.
>>
>>    Here are the results of running my bash script :
>>
>>    is 135 charactersktdfde.co.uk:80/**SetupddfImporter1020.exe<http://charactersktdfde.co.uk:80/SetupddfImporter1020.exe>
>>    <http://charactersktdfde.co.**uk/SetupddfImporter1020.exe<http://charactersktdfde.co.uk/SetupddfImporter1020.exe>
>> >
>>
>>    STATUS: HTTP/1.1 400 Bad Request
>>    **** HEADER ****
>>    Transfer-Encoding: chunked
>>    Date: Tue, 10 Apr 2012 21:47:21 GMT
>>    Connection: close
>>    Server: AmazonS3
>>    **** CONTENT ****
>>       [[ skipped ]]
>>    HTTP WARNING: HTTP/1.1 400 Bad Request - 135 bytes in 0.027 second
>>    response time |time=0.027087s;;;0.000000 size=135B;;;0
>>
>>    Here is what should appear:
>>
>>    http://update.efefktdfde.co.**uk:80/SetupddfImporter1020.exe<http://update.efefktdfde.co.uk:80/SetupddfImporter1020.exe>
>>    <http://update.efefktdfde.co.**uk/SetupddfImporter1020.exe<http://update.efefktdfde.co.uk/SetupddfImporter1020.exe>>
>> is 1460
>>
>>    characters
>>    STATUS: HTTP/1.1 200 OK
>>    **** HEADER ****
>>    x-amz-id-2:
>>    lmJo9jgflJdp+**ehTirekL19lXFY5KsNJ13UkiSWlNji**WzeYtVJ1OX7VIDZrsMNUJ
>>    x-amz-request-id: 7D72700CDF05E228
>>    Date: Tue, 10 Apr 2012 21:47:13 GMT
>>    x-amz-meta-cb-modifiedtime: Fri, 07 Oct 2011 03:36:32 GMT
>>    Last-Modified: Mon, 24 Oct 2011 20:41:44 GMT
>>    ETag: "**ca684ddfa09409f8890e8c92bc68f6**19"
>>    Accept-Ranges: bytes
>>    Content-Type: application/octet-stream
>>    Content-Length: 6056760
>>    Server: AmazonS3
>>    **** CONTENT ****
>>       [[ skipped ]]
>>    HTTP OK: HTTP/1.1 200 OK - 1460 bytes in 0.122 second response time
>>    |time=0.122165s;;;0.000000 size=1460B;;;0
>>
>>    In the bash script I am using the syntax:
>>
>>    test=$(cat /tmp/updates.txt | grep ServerFileName | awk
>>    'BEGIN{FS="="}{print $2}' | grep HHR)
>>    command="$check_http -v -N -H update.efefktdfde.co.uk
>>    <http://update.efefktdfde.co.**uk/ <http://update.efefktdfde.co.uk/>>
>> -u"/"$test"
>>
>>
>>    If I just do test=SetupddfImporter1020.exe then call command it
>>    works fine, so I would think its my variable however if I run a If
>>    statement to check if the one generating by the awk command is the
>>    same as  test=SetupddfImporter1020.exe it says they are equal/
>>
>>    This is driving me round the bend, any help would be much appreciated!!
>>
>>
>>
>>
>> ------------------------------**------------------------------**
>> ------------------
>> Better than sec? Nothing is better than sec when it comes to
>> monitoring Big Data applications. Try Boundary one-second
>> resolution app monitoring today. Free.
>> http://p.sf.net/sfu/Boundary-**dev2dev<http://p.sf.net/sfu/Boundary-dev2dev>
>>
>>
>>
>> ______________________________**_________________
>> Nagiosplug-help mailing list
>> Nagiosplug-help at lists.**sourceforge.net<Nagiosplug-help at lists.sourceforge.net>
>> https://lists.sourceforge.net/**lists/listinfo/nagiosplug-help<https://lists.sourceforge.net/lists/listinfo/nagiosplug-help>
>> ::: Please include plugins version (-v) and OS when reporting any issue.
>> ::: Messages without supporting info will risk being sent to /dev/null
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-plugins.org/archive/help/attachments/20120415/30987c06/attachment.html>


More information about the Help mailing list