Friday, January 11, 2013

Monitor your UPS using a raspberry pi: apcupsd works under Slackware 14.0

This is very easily done using tools built by others. Simply compile the program using the standard drill using this Slackbuild. Install the package and modify the apcupsd config file to match the cable/communication settings to the device. You can also make an entry in /etc/rc.d/rc.local to start the service automatically at boot up, and you're good to go. Well, at least, it worked for me. I hope it works for you!

Here's the output from the command line utility:

root@rp-1:~#: apcupsd status

APC      : 001,036,0903
DATE     : 2013-01-11 09:39:55 -0700  
HOSTNAME : rp-1
VERSION  : 3.14.10 (13 September 2011) slackware
UPSNAME  : rp-1
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2013-01-11 09:38:58 -0700  
MODEL    : Back-UPS XS 1200 
STATUS   : ONLINE 
LINEV    : 120.0 Volts
LOADPCT  :  12.0 Percent Load Capacity
BCHARGE  : 100.0 Percent
TIMELEFT :  99.8 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
SENSE    : Medium
LOTRANS  : 097.0 Volts
HITRANS  : 139.0 Volts
ALARMDEL : 30 seconds
BATTV    : 27.1 Volts
LASTXFER : Automatic or explicit self test
NUMXFERS : 0
TONBATT  : 0 seconds
CUMONBATT: 0 seconds
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x07000008 Status Flag
SERIALNO : JB0609014887  
BATTDATE : 2006-02-22
NOMINV   : 120 Volts
NOMBATTV :  24.0 Volts
NOMPOWER : 780 Watts
FIRMWARE : 8.g1 .D USB FW:g1 
END APC  : 2013-01-11 09:39:55 -0700  

Tuesday, January 8, 2013

A nice Windows hack: Substitute the bash shell to replace CMD

Going back to the Windows command line is always a painful experience. The pain is only magnified if you're used to using a unix shell, like bash. Luckily, relief is available via a free download and a Windows registry hack.

First, you'll need a replacement shell. There are a few available. I tested two.

  • Win-Bash This is a very lightweight tool. It only requires 13M of disk space and there are about 120 files with many standard utilities included. This setup ended up being much more capable than I had originally thought. Even though the bash version offered is several years old, it may be enough to meet your needs. Personally, I opted for a more comprehensive solution, below...
  • cygwin This is a large set of unix/linux applications that have been ported to the Windows environment. It can be installed piecemeal, and the base environment includes several shell options, including bash. The downside is that the basic install requires about 100M of disk space.

To add a final piece to the puzzle, and make executing the shell much more convenient, you'll need to tweak the Windows workstation a little bit. After installing the bash-capable environment of your choice, the next step is to create a batch file and tweak some registry settings. When these fixes are in place, it will enable you to invoke bash using the standard right-click menu context.

Create a startup batch file, my_bash.bat

@echo off
cd /D "%1"
SHELL=c:\cygwin\bin\bash.exe
PATH=c:\cygwin\bin;%PATH%
bash -i

Navigate to the proper position into the registry (caution! whenever fiddling with the registry!) using the registry editing tool of your choice:

\My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell

Add a new key using a descriptive name for the environment you've chosen. I installed both and chose win-bash and cygwin

Note that the value of default REG_SZ key assigns the name that will be shown in the right-click menu.

Next, add one more subkey below that new key:

\My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\cygwin\Command

The default REG_SZ for this subkey is the code that is executed. Link this to the batch file.


cmd /c c:\cygwin\my_bash.bat "%1"

Voila! Test it using the Windows explorer shell.

After this environment is installed other bonus factors can start to accumulate, too. You can start writing simple bash scripts to automate common Windows tasks, or not. In any case, the unix scripting language(s) offers much more robust and consistent environment(s) for getting things done. If that were not incentive enough all by itself, here are some other things that I have tested as working, too. You'll need to install more than the base layer of cygwin, though.

  • networking components. I installed ssh with heimdahl kerberos. That enables ssh sessions to be authenticated by active directory, i.e. without entering a passowrd.
  • gnu compiler tools. Now, you can compile your standard C/C++ code that will execute under Windows without having the Microsoft tools.
  • X11. Run remote X-applications!

As you can see, although I've only scratched the surface here, the Windows environment can be made more comfortable for those used to running Linux! Cygwin is the key.

edited: 2013-08-30, fix registry path