Talk:User Jobs

From MythTV Official Wiki
Revision as of 17:34, 12 February 2009 by Daid (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

%DESCRIPTION% how do I pass arguments in quotes, for example

if %DESCRIPTION% contains spaces would be split into many args $3 $4 $5 "%DESCRIPTION%" should be $1 and only $1

Error description

I would be handy if my script could pass back a textual description of what went wrong if the script fails. HighInBC 18:42, 18 April 2008 (UTC)


MythTV 0.21 always reports "Successfully Completed." when a user job has ended, no mather what. I've hacked together this php script:

#!/usr/bin/php
<?php
#include "xml2array.php";

$config = xml2array("/home/mythtv/.mythtv/config.xml");

$backend = $config['Configuration']['UPnP']['MythFrontend']['DefaultBackend'];
mysql_connect($backend['DBHostName'], $backend['DBUserName'], $backend['DBPassword']);
echo mysql_error();
mysql_select_db($backend['DBName']);
echo mysql_error();

if (count($argv) != 4)
{
    echo "Usage: ".$argv[0]." [jobID] [statusID] [comment]";
    exit -1;
}

$jobID = mysql_real_escape_string($argv[1]);
$statusNum = mysql_real_escape_string($argv[2]);
$comment = mysql_real_escape_string($argv[3]);

//Sleep 100ms. If we are run in background we'll update the status after MythTV set our status to succes.
usleep(100000);

mysql_query("UPDATE jobqueue SET status = '".$statusNum."', comment = '".$comment."' WHERE id = '".$jobID."';");
echo mysql_error();
?>

(xml2array from: http://nl3.php.net/manual/en/function.xml-parse.php#87920)

I then use it as:

#!/bin/sh

JOBID=$1
/usr/local/bin/update_job_state.php $JOBID 304 "Failed because I always fail" &

(Note the "run in background", as MythTV updates the state to succes after your process has ended. Running it in background with a slight delay will update the status after that.)

with the user job:

/path/to/script "%JOBID%" "%DIR%" "%FILE%"

I hope this helps someone. --Daid 17:34, 12 February 2009 (UTC)