Tag Archives: script

Zabbix Unsupported Items Status

Posted on .

Following on from the zabbix status script, I have put togethor another script to list any unsupported items on agents.

For an item to go unsupported, it usually means something is wrong with the agent, so I add this script to /etc/cron.hourly.

The SQL query to get the list of unsupported items is,

Download
  zabbix-unsupported-status.sh (1.3 KiB, 2,522 hits)

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,291 hits)

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,782 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,817 hits)