daily pastebin goal
70%
SHARE
TWEET

binblog

a guest Oct 4th, 2008 282 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use diagnostics;
  4. use POSIX qw(setsid);
  5. use Time::HiRes qw(usleep);
  6. use Data::Dumper;
  7.  
  8. my $lpstat = "/usr/bin/lpstat";
  9. my $ledbin = "/usr/local/sbin/led";
  10.  
  11. my @ledidle  = ("on", "off", "off");
  12. my @ledstate = @ledidle;
  13. my @ledsaved;
  14.  
  15. if (1){
  16.         fork && exit;
  17.         open STDIN,  "/dev/null"  or die "STDIN </dev/null: $!\n";
  18.         open STDOUT, ">/dev/null" or die "STDOUT >/dev/null: $!\n";
  19.         open STDERR, ">/dev/null" or die "STDERR >/dev/null: $!\n";
  20.         setsid();
  21. }
  22.  
  23. my $killed = 0;
  24. $SIG{TERM} = sub { $killed = 1; };
  25. $SIG{INT}  = sub { $killed = 1; };
  26.  
  27. while (1){
  28.         my @jobs = `$lpstat -o`;
  29.         my $jobcount = scalar @jobs;
  30.         if ($jobcount > 0){
  31.                 my $popped = pop @ledstate;
  32.                 unshift @ledstate, $popped;
  33.         }else{
  34.                 @ledstate = @ledidle;
  35.         }
  36.         if ($killed){
  37.                 @ledstate = @ledidle;
  38.         }
  39.         unless ("@ledstate" eq "@ledsaved"){
  40.                 system("$ledbin 1 $ledstate[0]");
  41.                 system("$ledbin 2 $ledstate[1]");
  42.                 system("$ledbin 3 $ledstate[2]");
  43.                 @ledsaved = @ledstate;
  44.         }
  45.         last if $killed;
  46.         usleep 333333;
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top