Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Continuous or timed?

by Bod (Parson)
on Dec 14, 2020 at 16:28 UTC ( [id://11125167]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Continuous or timed?
in thread Continuous or timed?

Thank you for all the information :)

Also, my general advice for running anything from cron is always use absolute paths

Following this advice I have used the full path so my cron entry is:

*/2 * * * * /usr/bin/perl /home/pi/Curtains/curtains.pl
If I use /usr/bin/perl /home/pi/Curtains/curtains.pl from the command line then the script runs but it doesn't run from cron. So I have enabled logging in /etc/rsyslog.conf and I get this logged:
Dec 14 16:12:01 eric CRON[10129]: (pi) CMD (/usr/bin/perl /home/pi/Cur +tains/curtains.pl) Dec 14 16:12:01 eric CRON[10128]: (CRON) info (No MTA installed, disca +rding output) Dec 14 16:14:01 eric CRON[10135]: (pi) CMD (/usr/bin/perl /home/pi/Cur +tains/curtains.pl) Dec 14 16:14:01 eric CRON[10134]: (CRON) info (No MTA installed, disca +rding output)
That explains why I am not getting any mail! But doesn't explain to me why the script is not running from cron. I have tried chmod 777 curtains.pl and chmod 755 curtains.pl.

What else should I be looking at to try and debug this problem>

Replies are listed 'Best First'.
Re^4: Continuous or timed?
by afoken (Chancellor) on Dec 14, 2020 at 19:46 UTC
    Dec 14 16:12:01 eric CRON[10128]: (CRON) info (No MTA installed, discarding output)

    No Mail Transport Agent installed. Guess why you did not get any mail. You need to install and configure something like nullmailer, exim, postfix, or - if you like the pain - sendmail.

    Alternatively, redirect output of all cron jobs to log files or pipe through logger(1).

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^4: Continuous or timed?
by haukex (Archbishop) on Dec 14, 2020 at 16:33 UTC
    What else should I be looking at to try and debug this problem

    Well, cron runs its entries with a very limited environment. So for example, if you've set a custom PERL5LIB environment variable, such as by using local::lib to install modules into your home directory, then those settings that perl gets via the environment won't be present. If that's the problem here, there are a couple of possible solutions: you could set PERL5LIB explicitly in the crontab, you could use lib, write a wrapper script, or, IIRC I once did this with an file in /etc/default, but that might be overkill on a simple "single-user" RPi.

Re^4: Continuous or timed?
by stevieb (Canon) on Dec 14, 2020 at 16:33 UTC

    What are the characteristics that you're using to identify that it runs at the CLI but not from cron?

      What are the characteristics that you're using to identify that it runs at the CLI but not from cron?

      It writes a timestamped line to a logfile very close to the beginning of the script.
      The logfile uses an absolute path.

      #!/usr/bin/perl use lib '.'; use Curtains::Control; use Bod::Config; use strict; my $DEBUG = 1; my $control = Curtains::Control->new; $control->log("Starting Curtain Controller") if $DEBUG;

      Could the location of the modules be an issue here as I've added use lib '.';?

        Could the location of the modules be an issue here as I've added use lib '.';?

        Yes, definitely, don't rely on the CWD either when running from cron, use an absolute path. Also, BTW, you can see what Perl is outputting by appending e.g. 2>/tmp/stderr to the crontab entry.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11125167]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-25 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found