+ Post New Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 39
*nix Thread, grep masters wanted in Technical; Originally Posted by plexer Thanks Tom. I can't seem to open that it just comes out gobbledegook when I un ...
  1. #16


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    338
    Quote Originally Posted by plexer View Post
    Thanks Tom.

    I can't seem to open that it just comes out gobbledegook when I un compress it.

    Ben
    It's perl, what did you expect

  2. #17

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    12,962
    Thank Post
    586
    Thanked 1,493 Times in 1,339 Posts
    Rep Power
    397
    Haha not in that way

    Ben

  3. #18


    tom_newton's Avatar
    Join Date
    Sep 2006
    Location
    Leeds
    Posts
    4,447
    Thank Post
    865
    Thanked 839 Times in 662 Posts
    Rep Power
    194
    tom@white-elephant:/tmp$ zcat plex.pl.gz
    #!/usr/bin/perl -Tw
    #

    use strict;

    my $colour = "Polka Dot";
    my $level = 0;

    while(<>)
    {

    if (m/<td width="197" height="30">(\w+) Toner Cartridge<\/td>/)
    {
    $colour = $1;
    }
    if (m/<font size="2">(\d+)%<\/font><\/td>/)
    {
    $level = $1;
    print "$colour: $level\n";
    }
    }
    tom@white-elephant:/tmp$

  4. Thanks to tom_newton from:

    plexer (17th October 2008)

  5. #19

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    12,962
    Thank Post
    586
    Thanked 1,493 Times in 1,339 Posts
    Rep Power
    397
    That works for me.

    Now to do the rest of the check

    Ben

  6. #20

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    12,962
    Thank Post
    586
    Thanked 1,493 Times in 1,339 Posts
    Rep Power
    397
    Ok here's a working script, many thanks to Tom for sorting this out for me.

    Ben
    Attached Files Attached Files

  7. #21


    tom_newton's Avatar
    Join Date
    Sep 2006
    Location
    Leeds
    Posts
    4,447
    Thank Post
    865
    Thanked 839 Times in 662 Posts
    Rep Power
    194
    Looks like you've got it working well Ben - thanks for reposting the perl we worked on via email.. hope it helps someone else

    Now go get "Learning Perl" (O'Reilly) it's good, it is.

  8. #22

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    12,962
    Thank Post
    586
    Thanked 1,493 Times in 1,339 Posts
    Rep Power
    397
    Yeah the only thing I've commented out is trying to get it to return a value as well as printing the output to stdout as it does now.

    Ben

  9. #23


    tom_newton's Avatar
    Join Date
    Sep 2006
    Location
    Leeds
    Posts
    4,447
    Thank Post
    865
    Thanked 839 Times in 662 Posts
    Rep Power
    194
    Quote Originally Posted by plexer View Post
    Yeah the only thing I've commented out is trying to get it to return a value as well as printing the output to stdout as it does now.

    Ben
    Did you not get that to work? TBH I got as far as working out what you were trying to do, but didn't check the code

  10. #24

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    12,962
    Thank Post
    586
    Thanked 1,493 Times in 1,339 Posts
    Rep Power
    397
    nagios takes the single line of text from stdout as a return but I'd seen some perl plugins that also returned the value as well.

    Such as exit $state;

    Allthough it may not be needed in my case as it works as we have it now.

    Just need to do add in some error checking like you mentioned becuase if I run it against a non k5440 printer for instance I presume it will baulk.

    Ben

  11. #25


    tom_newton's Avatar
    Join Date
    Sep 2006
    Location
    Leeds
    Posts
    4,447
    Thank Post
    865
    Thanked 839 Times in 662 Posts
    Rep Power
    194
    Would have thought so - though you might adapt it to detect the type of printer and find the correct URL automatically

  12. #26

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,476
    Thank Post
    1,305
    Thanked 469 Times in 306 Posts
    Blog Entries
    6
    Rep Power
    198
    Quote Originally Posted by plexer View Post
    I'm trying to create a plugin for nagios to get the consumables status for our Konica K5440dl printers.

    I tried a snmpwalk on one and it only goes so far so I was hoping to try and copy the HP 2600 one which uses wget to download the supplies status webpage to a temporary file and then extracts the details from that.

    Ben
    Can you post the one you use for the HP 2600 please?

  13. #27

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    12,962
    Thank Post
    586
    Thanked 1,493 Times in 1,339 Posts
    Rep Power
    397
    I'll look it up when I'm back at work next week.

    Ben

  14. #28
    ind1ekid's Avatar
    Join Date
    Jul 2008
    Location
    Nottinghamshire
    Posts
    82
    Thank Post
    6
    Thanked 16 Times in 13 Posts
    Rep Power
    14
    A bit off topic, but i didnt see the point making a new thread for this question what with all the linux scripting goin on here!
    I want to copy a set of folders to another folder, but log what files are processed at the same time to a text file:

    so i got something like this, but my file ends up empty

    Code:
    cp -R -v /Source /Destination > /Destination/Log.file
    Do i need to use cat and pipe it in there somehow?
    Cheers in advance peeps

  15. #29

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,855
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    181
    Quote Originally Posted by ind1ekid View Post
    so i got something like this, but my file ends up empty

    Code:
    cp -R -v /Source /Destination > /Destination/Log.file
    Works for me..

    $ cat Destination/log
    `Source/file2' -> `Destination/Source/file2'
    `Source/file1' -> `Destination/Source/file1'
    $

  16. #30


    tom_newton's Avatar
    Join Date
    Sep 2006
    Location
    Leeds
    Posts
    4,447
    Thank Post
    865
    Thanked 839 Times in 662 Posts
    Rep Power
    194
    cp -Rv ./baz/ ./bar/ > foo

    seems to work here

    tom@flying-squirrel:/tmp/foo$ cat foo
    `./baz/' -> `./bar/baz'
    `./baz/flibb' -> `./bar/baz/flibb'
    `./baz/quux' -> `./bar/baz/quux'

  17. Thanks to tom_newton from:

    ind1ekid (30th October 2009)

SHARE:
+ Post New Thread
Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. WANTED: Tablet PC
    By binky in forum General Chat
    Replies: 3
    Last Post: 26th October 2007, 01:45 PM
  2. audio wanted..
    By russdev in forum General EduGeek News/Announcements
    Replies: 0
    Last Post: 4th December 2006, 09:15 AM
  3. Grep syntax for multiple srtings?
    By ChrisH in forum *nix
    Replies: 17
    Last Post: 14th October 2006, 08:20 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •