Ticket #4049: mythtv-miscellaneous_status_info-example_scripts.patch

File mythtv-miscellaneous_status_info-example_scripts.patch, 5.5 KB (added by sphery <mtdean@…>, 12 years ago)

example scripts for contrib directory

  • contrib/misc_status_info/myth_recent_recordings.pl

     
     1#!/usr/bin/perl -w
     2#
     3# Outputs information about the most-recently-recorded shows.
     4#
     5# Automatically detects database settings.
     6#
     7
     8# Includes
     9    use DBI;
     10    use Getopt::Long;
     11    use MythTV;
     12
     13# Some variables we'll use here
     14    our ($num_recordings, $live, $plain_text, $usage);
     15
     16# Default number of recent recordings to show
     17    $dnum_recordings = 5;
     18
     19# Provide default values for GetOptions
     20    $num_recordings = $dnum_recordings;
     21
     22# Load the cli options
     23    GetOptions('num_recordings|recordings|n=s' => \$num_recordings,
     24               'live'                          => \$live,
     25               'plain_text|plain|text'         => \$plain_text,
     26               'usage|help|h'                  => \$usage
     27              );
     28
     29# Print usage
     30    if ($usage) {
     31        print <<EOF;
     32$0 usage:
     33
     34options:
     35
     36--recordings [number of recordings]
     37
     38    Outputs information on the last [number of recordings] shows recorded by
     39    MythTV.
     40
     41    default:  $dnum_recordings
     42
     43--text
     44    Output information in plain text format (i.e. for inclusion in an e-mail
     45    notification).
     46
     47--live
     48    Include information on recent LiveTV recordings.
     49
     50--help
     51
     52    Show this help text.
     53
     54EOF
     55        exit;
     56    }
     57
     58# Connect to mythbackend
     59    my $Myth = new MythTV();
     60
     61# Get the list of recordings
     62    my $count = 0;
     63    my %rows = $Myth->backend_rows('QUERY_RECORDINGS Delete');
     64    foreach my $row (@{$rows{'rows'}}) {
     65        last unless $count < $num_recordings;
     66        my $show = new MythTV::Program(@$row);
     67    # Skip LiveTV recordings?
     68        next unless (defined($live) || $show->{'recgroup'} ne 'LiveTV');
     69    # Format the starttime
     70    # Since format_name() formats for filenames, use "placeholders" for
     71    # characters that are illegal on some filesystems.
     72        my $starttime = $show->format_name('%mslash%j, %gcolon%i %A');
     73        $starttime =~ s/slash/\//;
     74        $starttime =~ s/colon/:/;
     75        if (defined($plain_text)) {
     76            print("$starttime - $show->{'callsign'} - $show->{'title'} - $show->{'subtitle'}\r\n$show->{'description'}\r\n\r\n");
     77        }
     78        else {
     79            print("Recent Recordings:<div class=\"schedule\">") if ($count == 0);
     80            print("<a href=\"#\">$starttime - $show->{'callsign'} - $show->{'title'} - $show->{'subtitle'}<br /><span><strong>$show->{'title'}</strong> $starttime<br /><em>$show->{'subtitle'}</em><br /><br />$show->{'description'}<br /></span></a><hr />");
     81            print("</div>") if ($count == ($num_recordings - 1));
     82            print("[]:[]recording$count\[]:[]$starttime - $show->{'title'} - $show->{'subtitle'}\n");
     83        }
     84        $count++;
     85    }
     86
  • contrib/misc_status_info/myth_sensors.sh

    Property changes on: contrib/misc_status_info/myth_recent_recordings.pl
    ___________________________________________________________________
    Name: svn:executable
       + *
    
     
     1#!/bin/bash
     2#
     3# sensors.sh
     4# Retrieves sensors output and formats it for inclusion in the MythTV backend
     5# status page.
     6
     7# The following line outputs information to include the CPU temperature
     8# information in the backend status page.  Though the sensors output includes
     9# the °C unit marker, it is stripped out of the data before being placed in the
     10# output page, so the display value includes a proper HTML entity.
     11
     12#sensors | awk '/CPU Temp/ { printf "Current CPU Temperature: %s &#8451;.[]:[]temperature-CPU[]:[]%s\n", $3, $3 };'
     13
     14# The following lines output CPU and Motherboard temperature and CPU and Case
     15# fan speed information.  Modify the patterns (i.e. /CPU Temp/) to match the
     16# sensors output lines containing the data you want to grab (i.e. /Core0
     17# Temp/).  Continue adding lines to the awk program as desired to incude
     18# additional information.
     19
     20sensors | awk '
     21/CPU Temp/ {
     22  printf "Current CPU Temperature: %s &#8451;.[]:[]temperature-CPU[]:[]%s\n", \
     23         $3, $3
     24};
     25/M\/B Temp/ {
     26  printf \
     27  "Current Motherboard Temperature: %s &#8451;.[]:[]temperature-MB[]:[]%s\n", \
     28    $3, $3
     29};
     30/CPU Fan/ {
     31  printf "Current CPU Fan Speed: %s.[]:[]fan-CPU[]:[]%s\n", $3, $3
     32};
     33/Case Fan/ {
     34  printf "Current Case Fan Speed: %s.[]:[]fan-case[]:[]%s\n", $3, $3
     35};
     36' | sort
     37
     38# With appropriate authentication in place (i.e. using SSH Certificate
     39# Authentication), you may also retrieve sensors data from remote system (i.e.
     40# slave backends, remote frontends, etc.).  Do so with commands of the format
     41# below (provide an appropriate hostname in place of "slave" (3 places) and
     42# replace the awk script with one providing the desired information as shown
     43# above):
     44
     45#ssh -q slave sensors | awk '/CPU Temp/ { printf "Current CPU Temperature (slave): %s &#8451;.[]:[]temperature-CPU-slave[]:[]%s\n", $3, $3 };'
     46
     47# Alternatively, this information could be retrieved from an appropriate
     48# monitoring program (monit, mrtg) or by using SNMP, depending on the system
     49# and network configuration.