PCgeekdom.com - PC Tricks and Projects

Friday, November 30, 2007

X10: Fun with Home Automation

     

Quite a few years ago, X10 had a promotion, and gave away their Firecracker kit for almost free. It includes 2 plug-in modules, a handheld remote and a serial connecter transmitter. I have used this in the past to turn on Christmas lights with the remote control.

The serial connector it comes with, the ‘Firecracker’ allows for some very fun things. There are several Linux packages available that interface with the serial transmitter. The one I use is called heyu. It allows you to easily send commands to the X10 units like so: heyu fon A1. So to automate my Christmas lights, I just had to add two lines to crontab for on and off.

Another fun application of this system is alerting me if I have a new voicemail on my landline. I never remember to check for messages on my landline when I come home, so now I have it set to turn on a lamp whenever someone leaves me a voicemail!

Here is how it works. A feature of my voicemail services is that the system emails me a copy of every voicemail when it is left. I use Thunderbird for a mail client and leave it open on my Linux box. I use Thunderbirds filters to move any messages from the voicemail service to a voicemail folder. I use an add-on, Mailbox Alert, that can watch a particular folder, and can run a command when a new message arrives, so I have it set that whenever a new email from my voicemail service comes in it issues this command: heyu fon A2, turning on my lamp alerting me of a new voicemail.


Sunday, October 07, 2007

Bash: Automatically make/update a symbolic link to the newest file in a directory

     

I needed a script that could monitor a directory for file changes, and upon any changes create or update a symbolic link to the newest file in the directory. For this particular application, I was interested only in mpg files, and wanted the script to only monitor and link to mpg files.
This is what I came up with:


echo $$ > /home/vlc/video/watch_dir.pid
touch /tmp/watch_dirb.$$
while true
do
ls /home/vlc/video/FolderName -l --hide='newestfile.mpg'| \
grep mpg > /tmp/watch_dira.$$

diff /tmp/watch_dira.$$ /tmp/watch_dirb.$$ || \
ln -sf `ls /home/vlc/video/FolderName -lt \
--hide='newestfile.mpg' | grep mpg | head -n 1 | awk '{print $8}'` \
/home/vlc/video/FolderName/newestfile.mpg

cp /tmp/watch_dira.$$ /tmp/Watch_dirb.$$
sleep 60
done

There is probably a better method, but this seems to work well.
Script Explanation:
The first line writes the scripts process id to file to make it easier to terminate the script e.g. kill `cat watch_dir.pid`
The directory monitoring is done by writing the folder contents (using ls) to a tmp file, and then comparing the contents of the current file, filea, with the file populated from the last check, fileb.
If diff does detect a change then this command is executed:
ln -sf `ls /home/vlc/video/FolderName -lt --hide='newestfile.mpg' | grep mpg | head -n 1 | awk '{print $8}'` /home/vlc/video/FolderName/newestfile.mpg
This line creates a symbolic link named newestfile.mpg pointed to the newest file in that directory. The newest file is determined by ls -lt, it hides newestfile.mpg so as not to create a link to the link. It then uses grep to find just the mpg files and takes the top entry with head -n 1, it only needs the filename so only the 8th field is used. (Note: depending on your distro the filename may not be in the 8th field and the awk command may need adjusting. In my own testing, I have found that the filename is the 8th field in Ubuntu, but the 9th field in Fedora.
The script then waits for 1 minute and checks again.


Thursday, September 14, 2006

Windows Vista...

     

Windows has started handing out product keys for an evaluation copy of Windows Vista. Click here to sign up for one (requires MS Passport/Windows live account.) I signed up and downloaded the Vista ISO. Since I don't have an extra machine laying around to throw on a beta OS I decided to try it in my VMware Server, installation went pretty smoothly.
I haven't had a chance to dive too deep into the new MS beast but what I first noticed is how much it is becoming to look like a lot of many other operating systems. They now have a "sidebar" that you can fill with "gadgets" And instead of the good old Start button it is now a Windows circle thing.
I will admit my first concern is how MS has decided to not include a shortcut to the Run dialog on the Start menu by default. My reason for concern is because I have to provide tech-support over the phone and this will create yet one more battle...
Overall it is pretty interesting, since I get to play with it for free right now I can't complain. I'm sure I am "missing out" on a lot of the new 3d rendering goodness, since I am running it via VMware. They use a system called Windows Experience Index to decide how much "fluff" to add. Since I am just running it via VMware Server I got a base score of 1. Someday I may have to load Vista on a machine that can use its full power until then, I will continue to play with it virtually.


Saturday, June 17, 2006

Cheap Networking Troubleshooter: Loopback Plug

     

A loopback plug can be very useful in testing and troubleshooting network problems. The loopback plug will cause the link light on a device, (a network card, switch, router, etc.) to come on. This is a very quick and cheap way to test simple network cabling problems. To make a loopback plug you just need to connect the transmit and receive lines together. (See picture.) Of course if you have some money to throw around you could buy a network tester a little bit more advanced, Fluke Networks offers a wide range of portable network testing equipment.


Monday, May 01, 2006

Featured Freeware: Audacity - Audio Editor & Recorder

     

If you have ever had the need or want to be able to easily create or edit a sound file, the open-source software Audacity is just what you are looking for.

Audacity is a free, easy-to-use audio editor and recorder for Windows, Mac OS X, GNU/Linux, and other operating systems. You can use Audacity to:

  • Record live audio.
  • Convert tapes and records into digital recordings or CDs.
  • Edit Ogg Vorbis, MP3, and WAV sound files.
  • Cut, copy, splice, and mix sounds together.
  • Change the speed or pitch of a recording.
  • And more! See the complete list of features.


Thursday, April 20, 2006

Basic Linux Tips and Tricks

     

As a relative Linux Newbie I have a lot yet to learn about our favorite open-source OS. I can however share a few of the tips and tricks I have found so far while working/playing with Linux.

While in a console window:
The Tab key - you can use the Tab key to autocomplete a command. For example if you have a file "thisisareallylongfilename.txt" and in the command line you type "pico thisis" and press tab it will complete the command to "pico thisisareallylongfilename.txt" for you.
Up Arrow - scrolls through previously entered commands
top - similar to Windows Task Manager, makes it easy to see and kill process.
pstree - prints the system tree of processes
cal - Displays a calendar, other options to try: cal -3, cal 7 1776
use echo and python as a scientific calculator: echo 'print (148+25)/(100E6)' | python
wget - a good quick downloader: wget http://...../file.ext
Use a stack to hold directory locations:
pushd . - pushes current directory to top of a stack
popd
- pops and switches to the directory at the top of the stack
time cat
- Start a stopwatch type Ctrl-D to stop and display time, to time how long a process takes just place time in front of the command.
man "command" - If you are unsure of how to use a command, man (manual) will display the documentation for that command. For example you could type man man to get the manual's manual.

These are just a few of the many many commands that can make using Linux easier, for more information on basic Linux, check out Linux.com and Unix Guide.


Wednesday, April 12, 2006

Shortcuts for Windows - Use the Windows Key

     

There are many useful shortcuts in the world of PCs. One of my favorite ways of saving a trip from my keyboard to the mouse is to use the Windows Run dialog box. The quickest way to open it up is by pressing Windows key + R. With Run you can open up most anything, below is a list of some regularly used applications. If you know the file name for the program you want to open, just try typing it in and hitting enter.

calc - Windows Calculator
notepad or notepad++ - Text Editor
cmd - Command Prompt (use command for Win95-WinME)
msconfig - Configure Various System settings like startup
msinfo32 - Displays Windows XP System Information
regedit - Windows Registry Editor
winipcfg - IP Configuration for Win95-WinME

iexplore - Internet Explorer
firefox - If you are cool
msimn - Outlook Express
outlook - MS Outlook
winword - Microsoft Word

dvdplay (uses Windows Media Player for DVD playback)
sol - Solitaire
freecell - FreeCell
mshearts - MS Hearts

I might also mention some of the Windows key's other great uses:
Windows key + d - Takes you to the desktop and back
Windows key + e - Opens Windows Explorer
Windows key + f - Run a search
Windows key + l - Logout or Lock your Windows Session (WinXP)
Windows key + Pause/Break - Opens System Properties