daily pastebin goal
69%
SHARE
TWEET

binblog

a guest Oct 7th, 2008 249 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 File::Find;
  7.  
  8. my $cupsq  = "/var/spool/cups";
  9.  
  10. my @ledidle  = (1, 0, 0, 0);
  11. my @ledstate = @ledidle;
  12. my @ledsaved;
  13.  
  14. if (1){
  15.         fork && exit;
  16.         open STDIN,  "/dev/null"  or die "STDIN </dev/null: $!\n";
  17.         open STDOUT, ">/dev/null" or die "STDOUT >/dev/null: $!\n";
  18.         open STDERR, ">/dev/null" or die "STDERR >/dev/null: $!\n";
  19.         setsid();
  20. }
  21.  
  22. my $killed = 0;
  23. $SIG{TERM} = sub { $killed = 1; };
  24. $SIG{INT}  = sub { $killed = 1; };
  25.  
  26. while (1){
  27.         my $jobcount = 0;
  28.         find ( sub { $jobcount++ if ("d" eq substr($_,0,1)) }, $cupsq);
  29.         if ($jobcount > 0){
  30.                 my $popped = pop @ledstate;
  31.                 unshift @ledstate, $popped;
  32.         }else{
  33.                 @ledstate = @ledidle;
  34.         }
  35.         if ($killed){
  36.                 @ledstate = @ledidle;
  37.         }
  38.         unless ("@ledstate" eq "@ledsaved"){
  39.                 set_led (1, $ledstate[0]);
  40.                 set_led (2, $ledstate[1]);
  41.                 set_led (3, $ledstate[2]);
  42.                 @ledsaved = @ledstate;
  43.         }
  44.         last if $killed;
  45.         usleep 100000;
  46. }
  47.  
  48. sub set_led{
  49.         my $led     = shift;
  50.         my $state   = shift;
  51.         my $sysfile = "/sys/class/leds/alix:$led/brightness";
  52.         open my $fh_out, ">$sysfile" or die "$sysfile: $!\n";
  53.         print $fh_out "$state\n";
  54.         close $fh_out;
  55. }
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