Tag Archives: perl

backuppc: Use of qw(…) as parentheses is deprecated

Posted on .


If you upgrade Perl to 5.13.5 or beyond, backuppc will begin to spew this warning at every oppurtunity. Debian/wheezy currently has these warnings on startup and in backuppc logs.

Debian bug #650522 suggests surrounding each use of qw(…) with rounded parenthesis: (qw(…)). There are a lot these used throughout backuppc, so I took a slightly less ingenious but just as effective route.

By adding: “no warnings 'deprecated';” to the beginning of each file that uses qw(…), the warnings are suppressed. This change can be scripted by using the following one-liner:

The location /usr/share/backuppc/lib/BackupPC/ is used on Debian/wheezy and may need adjusting for other distros.


mythtv-dvb-reload.pl

Posted on .

I’ve been having problems with my Hauppauge WinTV-NOVA-T 500 Dual DVB-T Tuner. Using MythTV every day or so one of the tuners on the card would no longer lock onto any channels. I wasn’t the only one.

As I don’t have any errors in logs, I can hardly troubleshoot. So I just automate what I have been doing, and that is,

  • Check the Encoders are idle
  • Stop Myth Backend
  • Unload the v4l driver, dvb_usb_dib0700
  • Reload the v4l driver
  • Restart Myth Backend

The only problem is I can’t just simply put this in a crontab entry, else I will get interrupted and split recordings.

The script does the above, but only if all the encoders are idle. It checks the xml feed on the backends status port (ie. http://localhost:6544/xml) for the encoder status and will perform the 4 tasks once an hour. If when the next hour comes around and MythTV is busy recording, the script will check each minute until they are idle.

To help you mould it to your system, the url, port, sleep times and the commands that are run can all be modified at the beginning of the scripts.

The script is relatively silent by default, stating it is being run and spurting out errors should they occur. If you want to see what is happening however a -v commandline option shall output something like,

20080215 19:13.41:debug: Fetching 'http://localhost:6544/xml'
20080215 19:13.41:debug: Begin XML parser.
20080215 19:13.41:debug: XML::Parser -> Found element '<Encoders>'
20080215 19:13.41:debug: XML::Parser -> Found element '<Encoder>'
20080215 19:13.41:debug: XML::Parser -> Attribute 'id' = 1
20080215 19:13.41:debug: XML::Parser -> Attribute 'state' = 4
20080215 19:13.41:debug: End XML parser.
20080215 19:13.41:debug: Encoders are busy, waiting 60 seconds.
20080215 19:14.41:debug: Fetching 'http://localhost:6544/xml'
20080215 19:14.41:debug: Begin XML parser.
20080215 19:14.41:debug: XML::Parser -> Found element '<Encoders>'
20080215 19:14.41:debug: XML::Parser -> Found element '<Encoder>'
20080215 19:14.41:debug: XML::Parser -> Attribute 'id' = 1
20080215 19:14.41:debug: XML::Parser -> Attribute 'state' = 0
20080215 19:14.41:debug: XML::Parser -> Found element '<Encoder>'
20080215 19:14.41:debug: XML::Parser -> Attribute 'id' = 2
20080215 19:14.41:debug: XML::Parser -> Attribute 'state' = 0
20080215 19:14.41:debug: XML::Parser -> Found element '<Encoder>'
20080215 19:14.41:debug: XML::Parser -> Attribute 'id' = 3
20080215 19:14.41:debug: XML::Parser -> Attribute 'state' = 0
20080215 19:14.41:debug: XML::Parser -> Found element '<Encoder>'
20080215 19:14.41:debug: XML::Parser -> Attribute 'id' = 4
20080215 19:14.41:debug: XML::Parser -> Attribute 'state' = 0
20080215 19:14.41:debug: End XML parser.
20080215 19:14.41:debug: Encoders are idle, begin restart.
20080215 19:14.41:debug: Executing: '/etc/init.d/mythtv-backend stop'
Stopping MythTV server: mythbackend .
20080215 19:14.41:debug: Executing: 'rmmod dvb_usb_dib0700'
20080215 19:14.41:debug: Executing: 'modprobe dvb_usb_dib0700'
20080215 19:14.42:debug: Executing: '/etc/init.d/mythtv-backend start'
Starting MythTV server: mythbackend .
20080215 19:14.42:debug: Backend and Driver reloading complete.
20080215 19:14.42:debug: Sleeping for 3600 seconds. zZz.

You need to run this script as root.

I may modify this should I find out what is triggering the problem. I’d prefer to only restart Myth when it happens.
Download
  mythtv-dvb-reload.pl (5.1 KiB, 1,586 hits)

directory_monitor.pl – Monitor directory for file changes

Posted on .

I wrote this perl script to monitor a directory for changes in files such as ,

  • Created
  • Deleted
  • Modified

A directory is given on the command-line and the script continuously checks for changes until it is halted (ctrl+c).

Example output,

$ ./directory_monitor.pl /tmp/

Monitoring directory: /tmp/
(ctrl+c to halt)

20080209.145857 : test.txt Created. [0b]
20080209.145904 : test.txt Size changed to 375b (up 375b)

I was having issues with MythTV prematurely deleting recorded shows, and this script proved its worth in determining when they were deleted.

Download
  directory_monitor.pl (4.6 KiB, 4,128 hits)

pingstatus.pl — Check for server downtime.


Wanting to continuously check if a server is losing connectivity, I quickly put togethor a small perl script to do the job.

Open the file and edit the variables to determine debug status, email details, server ip etc.

By default it sends a ping every second. If this test fails 5 times in a row, a report is sent via mail.

Disable debug for it to run silently in the background.

pingstatuspl-check-for-server-downtime-image1

Download
  pingstatus.pl (2.4 KiB, 1,379 hits)

exifsort.pl – Sort digital images by EXIF date.


I use 2 digital cameras, and my phone, to take pictures nearly every day. I came accross a perl script written by Lars Strand. This copied photos from CAM0001.JPG to a date formatted file such as 20070113.0900.JPG.

I decided to take this as a base, and change it into something that suited my own needs.

The script will take directories on the command-line and copy any pictures found to a target directory set within the script. It then creates a file and directory structure based on the EXIF time/date found in the JPEG.

For example

/source/CAM0001.JPG

now becomes

/target/2007/11.nov/20070113.0900.jpg

making the files easy to find and splitting them into months.

The script produces an output such as,

ExifSort v1.0 - http://www.nooblet.org/exifsort/

o Processing folder, /mnt/storage/Photos/100DSCIM/
o Processing folder, /mnt/storage/Photos/100CASIO/
CIMG0553.JPG -> 20071111_145714.jpg
CIMG0554.JPG -> 20071111_153500.jpg
CIMG0555.JPG -> 20071111_153529.jpg
CIMG0556.JPG -> 20071111_153614.jpg
CIMG0557.JPG -> 20071111_155707.jpg
CIMG0564.JPG -> 20071111_181839.jpg
CIMG0567.JPG -> 20071111_182038.jpg
CIMG0569.JPG -> 20071111_182659.jpg
CIMG0574.JPG -> 20071111_215006.jpg
CIMG0575.JPG -> 20071112_120508.jpg
CIMG0580.JPG -> 20071112_120723.jpg
CIMG0582.JPG -> 20071112_182803.jpg
o Processing complete.
12 files copied.
- 101 files the same.

The script checks modified dates and file sizes, and will compare the md5 checksum if it still isn’t sure, to know if it has already copied an existing file.

The photos folder in my family photo gallery is a direct result of this exif sorting script.

Requirements:

Download
  exifsort.pl (5.2 KiB, 2,294 hits)