Bob's Notepad

Notes on projects I have done and things I have learned saved for my reference and for the world to share

Tuesday, November 20, 2007

Using lock files in a script

When dealing with automated rsync backup scripts you sometimes run in to the issue of a large file taking longer than expected and cron launching another rsync -- eventually spiraling things down. The way to resolve this is create a lock file so that your script doesn't launch again if it is already running. Just put the following in your script under the #!/bin/sh statements:

if [ -f $LOCKFILE ]
echo Lock file exists...Exiting...
exit 0

This declares what the lock file is (you can make the file anything as long as the user running the script has access to read and write). Then it checks to see if the lockfile exists and exits if it does. If it doesnt exist, then it creates it.

All thats left is to add the following to the end of the script so that it cleanly deletes the lockfile after running:

exit 0

Thanks to @linuxchic for helping out :)

Labels: , ,

Reference Link

Tuesday, November 13, 2007

Installing XEN on Ubuntu 7.10 (amd64)

After finding how-to upon how-to that said to use "apt-get install ubuntu-xen-server" and repeatedly banging my head against the wall because it kept telling me the package wasnt found, I finally found the Xen page at the Ubuntu Community site that explained the situation. Apparently, there is no such package for amd64 kernels and you need to specify each needed package. Thankfully, they list the command you need over there:

(you do need to uncomment the universe repositories in /etc/apt/sources.list)

sudo aptitude install linux-image-xen bridge-utils libxen3.1 python-xen-3.1 xen-docs-3.1 xen-hypervisor-3.1 xen-ioemu-3.1 xen-tools xen-utils-3.1

Once you run that command, reboot the machine (may not be needed but won't hurt)

Now you'll need to edit /etc/xen/xend-config.sxp and uncomment the line (network-script network-bridge) and then comment (network-script network-dummy).

They also recommend adding "max_loop=64" to the end of the "loop" line in /etc/modules but this may not be needed for all people -- again, it won't hurt.

Now just reboot and it should all work.

NOTE: If your using i386, "apt-get install ubuntu-xen-server" should work for you. It's also possible that by the time you are reading this, the same command will work for amd64 but as of this post, it does not

Labels: , ,

Reference Link

Wednesday, November 07, 2007

100 Mac OSX Applications

Someone I've been following on Twitter posted a great list of his 100 top applications for Mac OSX. I wanted to link back to him from here. Click on the "Reference Link" at the bottom of this post.

Labels: ,

Reference Link

PVR150 with Set Top Box (KnoppMyth)

Last year I wrote a HOWTO that I put on the KnoppMyth Wiki. While I don't use KnoppMyth any longer and I feel that MythBuntu is a much easier solution I found myself needing information from that how-to and I apparently forget what I had named my document. After finding it I figured that I would post it here so I could find it if I needed to refer to it in the future. I included the updates that others had made as well.

Setting up KnoppMyth with one or more Hauppauge PVR-150 Cards using Dish Network or other Set Top Box

First, thanks to Mark who pointed me in the right direction at his site:

Reference System: KnoppMyth R5C7 with 2 Dish Network (Echostar) set top boxes running on two seperate Hauppauge PVR-150 PCI Cards (*NOT* the MCE version which does not have the IR Blaster)

Setting up KnoppMyth to use a set top box with the Hauppauge PVR-150's IR Blaster is actually pretty simple but there seems to be a lack of directions on exactly what needs to be done. Hopefully this will shed some light.

First of all, KnoppMyth already has lircd installed and running and should have already installed the drivers for the IR Blaster on the PVR-150. You can confirm this by checking for /dev/lircd. You should also see /dev/lirc and if you have a second PVR-150, you should see /dev/lirc1 (but you wont see an lircd1 at this time - we'll fix that later).
Step One

Make sure the lirc_pvr150 module is loading (needed for R5F27).

In some KnoppMyth distributions (like R5F27), lirc_i2c is loaded instead of lirc_pvr150. lirc_pvr150 is needed for the IR Blaster to work. To use lirc_pvr150, change following line in /etc/lirc/hardware.conf from:
MODULES="lirc_dev lirc_i2c"

MODULES="lirc_dev lirc_pvr150"

and reboot.
Step Two

Grab the latest firmware file. You can find a copy over at Mark's blog:

Note that this loads the firmware into RAM so it will increase your RAM usage. The alternative would be throwing the card in a windows machine and flashing it using Hauppauge's utilities.

Place that file in /usr/lib/hotplug/firmware on your KnoppMyth system and reboot. This step may be able to be skipped but there are some versions of the cards that have issues with IR lock ups.
Step Three

We need to find the codeset that your set top box uses. For my Dish Network / Echostar units, I used code set 1_28. If you need to find your code set, check out the blog listed at the top of this wiki and look at step #9 (you may need to look at step #6 to get an lircd.conf file as well). He has a script that you can download and use to find the code set for your set top box. If you have Dish Network tuner(s), then here is what you need in your lircd.conf file:
--- Begin file insert ---

begin remote

name blaster
bits 32
eps 0
aeps 0
plead 0
gap 333333
repeat_bit 0

begin raw_codes
name 0
name 1
name 2
name 3
name 4
name 5
name 6
name 7
name 8
name 9
name POWER
name CH_UP
name CH_DOWN
name MUTE
name VOL_UP
name EXIT
name GUIDE
name AV
name ENTER
name MENU
name MUP
name MDOWN
name MLEFT
end raw_codes

end remote

--- End File Insert ---

If you did the installation of KnoppMyth correctly and told the installer what remote you had, your remote control and IR receiver should already be up and running.
Step Four

We're actually almost done if you have only one tuner. All that is needed now is to have a script that mythtv can point to when it needs to change the channel. Again, Mark wrote a great script that works well. Paste this into a file called "change_channel" or something else that makes you happy and do "chmod +x change_channel". A good location for this script would be /usr/local/bin. Make sure your mythtv user has access to this script.
--- Begin Script ---

# make sure to set this string to
# the corresponding remote in /etc/lircd.conf
$remote_name = "blaster";

# Let's assume you don't need to press enter after you punch in a
# channel number. Change this to 1 if your cable box expects you press
# enter after each command
$needs_enter = 0;

# Change this to point to your rc executable
$rc_command = "/usr/local/bin/irsend";

# This subroutine actually sends the signal to the cable box
sub change_SIGNAL {
my($SIGNAL) = @_;
system ("$rc_command SEND_ONCE $remote_name $SIGNAL");

open F, ">> /var/log/channel.log";
print F "channel changing $SIGNAL\n";
close F;
print "channel changing $SIGNAL\n";

# Checks if $SIGNAL begins with a digit
# If it detects that the string is made up of digits, then it puts
# spaces between the digits. Ex. 1234 becomes 1 2 3 4
if ( $SIGNAL =~ /^\d+$/ )
my $length = length($SIGNAL);
my $counter = 0;
my $temp;

while( $counter < $length )
$temp .= substr($SIGNAL,$counter,1) ." ";

# argument we passed was not made up of digits, so it must be a
# command that does something other than channel changing on the
# cable box

# Do we need to send enter
if ( $needs_enter )
system ("$rc_command SEND_ONCE $remote_name ENTER");

--- End Script ---

If your set top box needs an enter key pressed after a channel is entered, change the appropriate value to "1" in the script instead of "0" ... For Dish Network, 0 works fine.
Step Five

Test your script. Simply do a "./change_channel xxx" where xxx is a valid channel number on your set top box. With a little luck, your set top box will change channels.

If your script changes the channel without issue, you're set. Now just tell MythTV to use the script when it needs to change the channel. Run mythtv-setup and go to the Input Connections and in the appropriate tuner fill in the blank for the script to change channels. Just put "/usr/local/bin/change_channel" and MythTV will automatically append the channel number each time it is needed.
Stop here unless you have more than one tuner
Step Six

If you have more than one tuner, you'll need to create a seperate PID for the second PVR-150 card. You do NOT need a seperate configuration file. If you only have one tuner, what are you doing reading this section? :)

Creating the second PID is rather simple. This command will start another process of lircd without affecting the first.

/usr/sbin/lircd --device=/dev/lirc1 --output=/dev/lircd1 --pidfile=/var/run/

This is dependant on the fact that /dev/lirc1 is already created -- If KnoppMyth was installed properly, it should have already detected your second PVR-150 and created that device. If this command worked properly, you should now see a /dev/lircd1 device.
Step Seven

Now you need to create a separate change channel script for this tuner. Just copy the change_channel script you created above to something such as change_channel_1 and do a chmod +x on it as well. Edit the file and change the $rc_command line to this:
$rc_command = "/usr/local/bin/irsend --device=/dev/lircd1";
Step Eight

Tell the second tuner to use this script when changing channels the same way we did in Step Four above
Step Nine

Now you probably want KnoppMyth to start the second instance of lircd on boot. To do that, create /etc/init.d/lirc1 and include these 2 lines:
#! /bin/sh
/usr/sbin/lircd --device=/dev/lirc1 --output=/dev/lircd1 --pidfile=/var/run/

Do a chmod +x on this file and now tell the system to export it to all run levels by doing "update-rc.d lirc1 defaults".
Howto by bibleboy @ 3:31am EDT 07/07/06
Edited by Bigbro @ 16:50 PT 09/18/06 -Fixed the ARG statement syntax.
Wikimarkup made the bracket 0 bracket appear incorrectly.
inserted a tilde infront of first bracket. Works with R5C7!
Edited by RBucci @ 7:59 ET 10/15/07 - Added new Step 1 for R5F27.

Labels: ,

Reference Link