Tag Archives: Linux

checkprocess.sh – Check process & restart

Posted on .

I have a process that has been crashing every few days, but needs to be running 24/7 to be effective. Until I find the time to seek out the cause, I need the process to be restarted.

This short SH script uses PS to check that the process is running, and if not, runs the given init-script to restart the service.

Syntax:

checkprocess.sh [process] [init-script]

Example:

checkprocess.sh myprocess /etc/init.d/myprocess

checkprocess.sh writes a log at /var/log/checkprocess.log, and sends an alert mail to root should the process require restarting.

Put the checkprocess.sh command into crontab to check regular for the crashed process. For debian the crontab entry would look similar to:
*/1 * * * * root /usr/local/bin/checkprocess.sh mythbackend /etc/init.d/myth-backend

Download
  checkprocess.sh (723 bytes, 2,333 hits)

exiv2 — compile issue

Posted on .

Being given a DVD of photos, I ran my exifsort script to sort the images into date stamped folders and found the camera that had taken the pictures had the year set to 2026.

I came accross a handy utility to modify the EXIF timestamp of the images called exiv2 at www.exiv2.org. Unfortunately Debians repository is horribly out of date, so I grabbed the source from their site.

I began with a ./configure and came accross this error:

configure: error: either specify a valid expat installation with --with-expat=DIR or disable XMP support with --disable-xmp

It was easily fixed by installing the libexpat1-dev package,
apt-get install libexpat1-dev

Exiv2 compiled nicely after that.

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, 2,800 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, 5,830 hits)