Archive for the 'PERL' category

Chilling with some SOM

November 8, 2009 12:12 am

What a busy weekend cleaning up the house with Mary.  Slowly I am getting my life back in order after moving for the 3rd time this year.

It feels good to listen to a some Sisters of Mercy, relay with a glass of wine and see what city council has in-store for us next week…

And there it is:

*1562 Authorize Grant Agreement with VOZ: Workers’ Rights Education for $50,000 to operate and maintain their day labor hire site in Portland as approved by Council  (Ordinance)

Good ‘Ol Randy slipping something by in the consent agenda that is politically unpopular.  Now I am not saying that there should not be a Day Labor center… just that the citizens have a right to have a say on this issue.

But enough with city stuff right now.  I have some PERL code to write for Forward Support to do credit card processing with A.net that will collect all the SOS requirements for political contributions.  I kinda look forward to this as it has been some time since I have used some of my code-fu.

Though for those that are really looking for a good time… check out ORESTAR for the new candidate filings… oh how I love transparent government.  Which remnds me of yet another PERL script I need to write for FS.

Cracking a NUT with code

November 18, 2008 9:48 pm

I got the gear that I lent to Amanda’s campaign back and am getting it set up for a project that me and a few friends are doing.  Today was mainly getting the PowerCom KIN-1500AP UPS up and running.  I ended up having to write some code to get the shutdown working properly.

See:

#! /usr/bin/perl
# little script that will wait till batteries are almost dead to power down
# if power comes back before then then NUT is restarted
# min battery level to start shutdown
$min_battery_level = 80;
# seconds to wait between poll of UPS status
$poll_interval = 10;
$upsc_bin = "/bin/upsc";
$logger_bin = "/usr/bin/logger";
$upsname = "black@localhost";
$ups_status = &get_ups_status();
$ups_battery_level = &get_ups_battery_level();
`$logger_bin -t $0 "called by NUT"`;
`$logger_bin -t $0 "UPS_STATUS is $ups_status"`;
`$logger_bin -t $0 "UPS_BATTRY is at $ups_battery_level"`;

while ( &get_ups_battery_level() > $min_battery_level ) {

   ### The UPS is back on line and we can exit
   if ( &get_ups_status() eq 'good' ) {
      `$logger_bin -t $0 "UPS_STATUS is good."`;
      `$logger_bin -t $0 "Restarting NUT and exiting $0"`;
      `/etc/init.d/nut restart`;
      exit 1;
   }
   else {
      foreach ( `$upsc_bin $upsname` ) {
         if ($_ =~ m/ups\.status/) {
            `$logger_bin -t $0 "$_"`;
            $ups_battery_level = &get_ups_battery_level();
            `$logger_bin -t $0 "battery.charge: $ups_battery_level"`;
            sleep $poll_interval;
         }
      }
   }
}
# If we get to this point the battery is really low and we need to shutdownp
`$logger_bin -t $0 "battery.charge is below $min_battery_level"`;
`$logger_bin -t $0 "Shutting system down"`;
`/sbin/shutdown -h -P now`;
########################################
sub get_ups_battery_level() {
   foreach ( `$upsc_bin $upsname` ) {
      if ($_ =~ m/battery\.charge/) {
            $charge = $_;
            $charge =~ s/(.*)(\:\ )(.*)/$3/ ;
            chomp ($charge);
      }
   }
   return $charge;
} #End of sub get_ups_battery_level()

sub get_ups_status() {
   foreach ( `$upsc_bin $upsname` ) {
      if ($_ =~ m/ups\.status/) {
         if ( $_ =~ m/OL/ ) {
            $status = "good";
         }
         else {
            $status = "bad";
         }
      }
   }
   return $status;
} #End of sub get_ups_status()

The CNC machine is working great.  I am still learning the intricacies of CAM and gcode… well that and waiting for the variable speed controller and mill ends to arrive.  I emailed the city to find out the process for selection on the CRC.  This week they are reviewing the applications and the beginning of December is when they will interview.  Jonathan over at Bikeportland.org posted a very telling story of why I feel that Citizen oversight of the police service is necessary:

PSU Cycling Club president Reuben Vyn and Officer Pryce. (Photos: Peter Welte, Story: BikePortland.org)

PSU Cycling Club president Reuben Vyn and Officer Pryce. (Photos: Peter Welte, Story: BikePortland.org)