Monday, October 06, 2008

mc2xml on ubuntu

I recently switched to mc2xml for grabbing TV listings from TitanTV. The service doesn't always respond in a timely manner and so I needed a script to retry a couple of times in case it failed the first time. Here is the bash script that I wrote to retry every 60 seconds for 15 minutes. I hope that it helps someone else.

#!/bin/bash

servicebusy=2
repeats=0
maxrepeats=15

cd /home/user/mc2xml
./mc2xml
errorcode=$?

echo Error Code == $errorcode

while [[ $errorcode -eq $servicebusy ]]; do
if [[ $repeats -ge $maxrepeats ]]; then
exit -1
fi
let "repeats += 1"
echo repeating in 60 seconds \( try $repeats of $maxrepeats \)
sleep 60
./mc2xml
errorcode=$?
done

mythfilldatabase --refresh-all --file 1 xmltv.xml
I run it every night with the following command in my crontab

39 2 * * 1-7 bash /home/user/mc2xml/do_mythfill_fixed.sh

Thursday, May 22, 2008

inadyn, opendns, and Ubuntu

I have been using DNS services from OpenDNS.org for a little while now, and I am very happy with some of the features that they provide such as URL shortcuts and finely grained internet filtering. However, in order to use the features, I have to keep my dynamic IP address up to date with their DNS-O-Matic service. Their list of clients includes inadyn, which is available through Ubuntu but doesn't include DNS-O-Matics ssl extensions and so I compiled my own version and installed it.

Here are the steps I followed:

  1. Download modified inadyn source code from OpenDNS -- wget http://www.opendns.com/support/ddns_files/inadyn.source.v1.99.zip
  2. Unzip the source code -- unzip inadyn.source.v1.99.zip
  3. sudo apt-get build-dep inadyn
  4. sudo apt-get install libcurl4-openssl-dev
  5. cd inadyn.source.v1.99
  6. make
  7. sudo cp -p bin/linux/inadyn /usr/local/sbin/.
  8. Create a script named inadyn in /etc/init.d so that it will launch automatically on startup.
    #! /bin/sh

    ### BEGIN INIT INFO
    # Provides: inadyn
    # Required-Start: $network
    # Required-Stop: $syslog
    # Should-Start: $named $syslog
    # Should-Stop: $syslog $network
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Dynamic IP Adress updater
    # Description: inadyn is a program that updates services such as
    # dyndns.org and dnsomatic.com when the host's external
    # external IP address changes.
    ### END INIT INFO

    set -e

    # /etc/init.d/inadyn: start and stop the inadyn daemon

    DAEMON=/usr/local/sbin/inadyn
    INADYN_ENABLE=true
    INADYN_OPTS=''
    INADYN_CONFIG_FILE=/etc/inadyn.conf

    test -x $DAEMON || exit 0

    . /lib/lsb/init-functions
    . /etc/default/rcS

    export PATH="${PATH:+$PATH:}/usr/sbin:/sbin:/usr/local/sbin"

    case "$1" in
    start)
    if "$INADYN_ENABLE"; then
    log_daemon_msg "Starting inadyn daemon" "inadyn"
    if [ ! -s "$INADYN_CONFIG_FILE" ]; then
    log_failure_msg "missing or empty config file $INADYN_CONFIG_FILE"
    log_end_msg 1
    exit 1
    fi
    if start-stop-daemon --start --quiet \
    --pidfile /var/run/inadyn.pid --make-pidfile\
    --exec $DAEMON
    then
    rc=0
    else
    rc=1
    fi
    if [ $rc -eq 0 ]; then
    log_end_msg 0
    else
    log_end_msg 1
    fi
    else
    if [ -s "$INADYN_CONFIG_FILE" ]; then
    [ "$VERBOSE" != no ] && log_warning_msg "inadyn daemon not enabled in /etc/init.d/inadyn, not starting..."
    fi
    fi
    ;;
    stop)
    log_daemon_msg "Stopping inadyn daemon" "inadyn"
    start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
    log_end_msg $?
    ;;
    restart)
    set +e
    if $INADYN_ENABLE; then
    log_daemon_msg "Restarting inadyn daemon" "inadyn"
    start-stop-daemon --stop --quiet --oknodo --exec $DAEMON || true
    sleep 1
    if start-stop-daemon --start --quiet \
    --pidfile /var/run/inadyn.pid --make-pidfile \
    --exec $DAEMON
    then
    rc=0
    else
    rc=1
    fi
    if [ $rc -eq 0 ]; then
    log_end_msg 0
    else
    log_end_msg 1
    fi
    else
    [ "$VERBOSE" != no ] && log_warning_msg "inadyn daemon not enabled in /etc/default/inadyn, not starting..."
    fi
    ;;

    *)
    echo "Usage: /etc/init.d/inadyn {start|stop|restart}"
    exit 1
    esac

    exit 0
  9. sudo update-rc.d -f inadyn defaults
  10. Create an inadyn.conf file in /etc
    background
    syslog

    update_period_sec 600 # Check for a new IP every 600 seconds
    secure

    # Enter your DynDNS username and password here
    username <USERNAME GOES HERE>
    password <PASSWORD GOES HERE>

    # What kind of host is being updated? Choices are dyndns@dyndns.org, statdns@dyndns.org, custom@dyndns.org
    dyndns_server_name updates.dnsomatic.com
    dyndns_server_url /nic/update?
    alias <DNS-O-Matic SERVICE 1 GOES HERE>
    alias <DNS-O-Matic SERVICE 2 GOES HERE>

  11. /etc/init.d/inadyn start

  12. all done inadyn is now installed and will keep DNS-o-Matic apprised of you IP address.

New MythTV Box

I just put together a new MythTV box with an Intel Core2 Duo E7200 processor and a Gigabyte GA-73PVM-S2H. My build was based on one I found on another blog, and so far I am very pleased with the results. I used MythBuntu 8.04 for the OS, and despite the fairly minimal install MythBuntu provides, I have gotten everything working rather quickly. I intend to document a couple of the tweaks that I have to make in order to get everything working just right.

Here is a list of the additional packages that I have installed so far with apt-get:

  • unzip
  • nvidia-glx-new
  • nvidia-settings
  • sysvconfig (I like to use the Fedora/RH style 'service' script to stop and restart services)
  • hdhomerun-config

Friday, December 21, 2007

MythFrontend over VNC

Sometimes I like to access my MythTV box over VNC. However, MythFrontend's default settings use OpenGL which doesn't play nicely with VNC. I found adding a parameter to the mythfrontend command forces it to use the QT painter instead of OpenGL which makes everything work perfectly (except for video of course). Since my MythTV box doesn't normally have a keyboard attached to it, and I find that using the remote to make changes in the setup can sometimes be tedious, so I use this trick to make things a little bit easier. Here's the command:

mythfrontend -O ThemePainter=qt

Friday, November 30, 2007

Circumventing restrictive firewalls using SSH for fun and profit

I occasionally need to find a way to route network traffic from my machine through another machine in order to circumvent a draconian firewall or a network resource on a private machine. I order to get started you'll need a shell account on the remote computer. This could be as simple as signing up for a free ssh account from a site like those listed here. You could also setup an SSH server like copSSH on your Windows machine if you don't have access to a Linux machine somewhere and don't want to be restricted by the restrictions placed on most free SSH accounts.

Once you have ssh access to the remote machine then you can fire up Putty. Enter in the hostname in the hostname field and then in the Connection->SSH->Tunnels configuration panel put 8080 in the "Source Port" box, select the Dynamic option, and click "Add". Click "Open" and then login to the remote host like normal.
If you happen to be on a machine that has openSSH installed, then you can just type "ssh -D <remote hostname>" to acheive the same effect.

After the connection has been established you should be able to set any of your internet based programs that can use a SOCKS proxy to use the address "localhost:8080" as a proxy server. All of your data will then be automagically rerouted through an encrypted connection between the two computers and appear to be originating from the remote host instead of your local machine. Some of the programs that work well with this method are Pidgin, Firefox, and bit torrent clients like Azureus.

Thursday, November 29, 2007

Pidgin Portable updated to version 2.3

I have packaged a version of PidginPortable using Pidgin 2.3 and the method that I described earlier for Pidgin 2.2.1. You can download the file from here:

http://www.mediafire.com/?8mmnmtxs9jc

edit:Pidgin did a quick update to version 2.3.1. Please use this new download link to get the latest version.

http://www.mediafire.com/?7g1p29yfyjx


UPDATE: PortableApps.com has released an official version of Pidgin 2.4 so I will no longer be updating my version. Thanks to all of you who used it while it was needed.

Monday, October 15, 2007

Suspend to RAM to save power

Today is Blog Action Day, and so I thought that I would write a bit about how I save energy while still maintaining an (almost) always on computer.

Every modern computer supports Suspend to RAM, but in my experience, few people use it. Most people either leave their computer on all of the time for convenience or turn it off when they are done with it in order to save power. Suspend to RAM allows you to have the best of both worlds very little power usage when it is suspended and instant availability when you are ready to use it again.

Basically, when your computer enters the Suspend to RAM (or goes to "sleep") everything inside the computer gets turned off except for the memory. This includes all of the fans, hard drives, video cards, etc. For all intents and purposes your computer will appear to be off except for possibly a small light somewhere on the computer that blinks to show that the computer is still on. When you wake the computer back up again, everything should appear exactly as it was before the computer went to sleep in less than 5 seconds.

Here are some simple tips on how to get started using Suspend to RAM mode on your Windows PC:

  1. Open the "Power Management" control panel icon (Start->Run->"powercfg.cpl" works too)
  2. Adjust the System Standby time to match your needs.
  3. I prefer to put my computer to sleep and wake it up with the power button. I want to enable this function, then click the "Advanced" tab and change the "When I press the power button on my Computer" setting to be "Standby".
Now you should be all set to go. Your computer should go to sleep after a short period of time, and it will wake back up when you press a key on the keyboard or press the power button on the computer again.

Unfortunately there are a lot of things that can go wrong with this process. The most common problem that I have encountered is that the computer doesn't shut down completely and the fans and hard drives are still running. In this case doing one of the two following tricks normally fixes the problem:
  • Disable the "Allow this device to bring the computer out of Standby" setting for all of your USB devices.
    • Right click on "My computer and select "Manage", then open the "Device Manager" (or Start->Run->"devmgmt.msc")
    • Double click on the device to bring up the properties window
    • Make sure that "Allow this device to bring the computer out of Standby" is not checked in the "Power Management" tab
  • Change the power scheme to "Portable/Laptop"
    • Open Power Options in the Control Panel (or Start->Run->"powercfg.cpl")
    • Change the Power Scheme to "Portable/Laptop"
    • Check to see whether the fans still run in Standby
    • If the problem is fixed, then you should be able to change the Power Options to custom times without a problem.
    • This solution may seem a little bit sketchy since it doesn't seem to change anything that you couldn't change already, but there is definitely something that gets reset with this hack. I once had a machine that wouldn't sleep properly and using this hack fixed the problem.
If you need more help, there are a couple of people with more detailed writeups that you can follow: (exoid.com) (jillesvangurp.com) (thegreenbutton.com)

So how much power does this actually save? On my desktop, which I consider to be fairly average, I used a Kill-A-Watt meter to measure the power draw of my computer. While running, the machine uses ~150 Watts. If I suspend the machine, then I only draw ~8Watts. For a 24-Hour period that is a savings of about 3.4 KW-Hrs!

 

Blogger Template by Blogcrowds