[Solved] Weekly cron job fails with fixes/30 on Debian 10

Have a MythTV related problem? Ask for help from other MythTV users here.

Moderator: Forum Moderators

Post Reply
gpw928
Junior
Posts: 51
Joined: Tue Feb 12, 2019 5:59 am
Location: Rural NSW
Australia

[Solved] Weekly cron job fails with fixes/30 on Debian 10

Post by gpw928 »

Hi,

I have recently upgraded to Debian 10 with MythTV from source fixes/30, and just got this in the mail:

Code: Select all

Message 318/318 Anacron <...my.domain>     Mar 21, 2020 07:47:52 am +1100
Date: Sat, 21 Mar 2020 07:47:52 +1100
To: root@mith.my.domain
Subject: Anacron job 'cron.weekly' on mith

/etc/cron.weekly/mythtv-database:
/etc/cron.weekly/mythtv-database: 17: /etc/cron.weekly/mythtv-database: USER: parameter not set
run-parts: /etc/cron.weekly/mythtv-database exited with return code 2
A quick look at /etc/cron.weekly/mythtv-database:

Code: Select all

line  7: set -e -u
line 17: if [ "$USER" = "" ]; then
The "set -e" is triggering the error exit when $USER is not set. I made the following change:

Code: Select all

line 17: if [ "X$USER" = "X" ]; then
Another option would be to add a USER definition to /etc/default/mythtv-backend.
Not sure which is best, nor how to log a bug report.
Last edited by gpw928 on Sun Apr 05, 2020 8:58 pm, edited 3 times in total.
wesnewell
Senior
Posts: 731
Joined: Mon Jun 23, 2014 6:54 pm
Location: Wylie TX, USA
United States of America

Re: Weekly cron job fails with fixes/30 on Debian 10

Post by wesnewell »

I ran into this a while back, and simply commenedt out the if user check since cron jobs are always run as root.
#!/bin/sh
# /etc/cron.weekly/mythtv-database script - check and backup mythconverg tables
# Copyright 2005/12/02 2006/10/08 Paul Andreassen
# 2010 Mario Limonciello
set -e -u
DBNAME="mythconverg"
DEBIAN="--defaults-extra-file=/etc/mysql/debian.cnf"
/usr/bin/mysqlcheck $DEBIAN -s $DBNAME
if [ -e "/etc/default/mythtv-backend" ]; then
. /etc/default/mythtv-backend
fi
# if [ "$USER" = "" ]; then
CMDPREFIX=""
# else
# CMDPREFIX="sudo -u $USER"
# fi
$CMDPREFIX /usr/share/mythtv/mythconverg_backup.pl
/usr/bin/logger -p daemon.info -i -t${0##*/} "$DBNAME checked and backed up."
# End of file.
BE/FE-Asrock AB350 Pro Ryzen 3 3200G, 6 atsc tuners. FE's-GF8200's Athlon II, Ryzen 3 2200G. Mythtv user since 2005.
User avatar
bill6502
Developer
Posts: 2307
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Weekly cron job fails with fixes/30 on Debian 10

Post by bill6502 »

The packaging tree for Debian is here: https://github.com/MythTV/packaging/blo ... ron.weekly
And @gpw928 was just pushed for v30, v31 and master. Thanks for spotting the issue.
gpw928
Junior
Posts: 51
Joined: Tue Feb 12, 2019 5:59 am
Location: Rural NSW
Australia

Re: Weekly cron job fails with fixes/30 on Debian 10

Post by gpw928 »

Thank you for that.

I just realised that I tested the change interactively, and that invalidated the testing ("dash -e" works differently when interactive).

The correct fix requires the failing command to explicitly tested, so lines 17 through 21 need to be replaced with this:

Code: Select all

CMDPREFIX=""
[ "X$USER" != "X" ] && CMDPREFIX="sudo -u $USER"
wesnewell
Senior
Posts: 731
Joined: Mon Jun 23, 2014 6:54 pm
Location: Wylie TX, USA
United States of America

Re: Weekly cron job fails with fixes/30 on Debian 10

Post by wesnewell »

Went through this a year ago.
viewtopic.php?f=36&t=3110
BE/FE-Asrock AB350 Pro Ryzen 3 3200G, 6 atsc tuners. FE's-GF8200's Athlon II, Ryzen 3 2200G. Mythtv user since 2005.
gpw928
Junior
Posts: 51
Joined: Tue Feb 12, 2019 5:59 am
Location: Rural NSW
Australia

Re: Weekly cron job fails with fixes/30 on Debian 10

Post by gpw928 »

My goal is to get the sources patched correctly so we won't have to go through it again.
User avatar
paulh
Developer
Posts: 909
Joined: Thu Feb 06, 2014 6:09 pm
Great Britain

Re: Weekly cron job fails with fixes/30 on Debian 10

Post by paulh »

I'm being lazy an can't be bothered to check the commits :roll: but I have a vague recollection of fixing this already maybe the changes weren't backported to fixes/30?
User avatar
bill6502
Developer
Posts: 2307
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Weekly cron job fails with fixes/30 on Debian 10

Post by bill6502 »

gpw928 wrote:
Sat Mar 21, 2020 9:40 pm
The correct fix requires the failing command to explicitly tested, so lines 17 through 21 need to be replaced with this:

Code: Select all

CMDPREFIX=""
[ "X$USER" != "X" ] && CMDPREFIX="sudo -u $USER"
FYI, a solution was pushed on 4/1: https://github.com/MythTV/packaging/blo ... ron.weekly
gpw928
Junior
Posts: 51
Joined: Tue Feb 12, 2019 5:59 am
Location: Rural NSW
Australia

Re: Weekly cron job fails with fixes/30 on Debian 10

Post by gpw928 »

bill6502 wrote:
Sun Apr 05, 2020 3:23 pm
FYI, a solution was pushed on 4/1: https://github.com/MythTV/packaging/blo ... ron.weekly
Thank you. I see that the code was changed to test "${USER:-}", which is instructive in the context (non-interactive, "set -e" active).
Post Reply