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

#!usr/bin/perl

Note you're missing a slash before usr. Also, my general advice for running anything from cron is always use absolute paths for everything in the crontab, i.e. "/usr/bin/perl /path/to/script.pl".

I am not getting emails with any errors from CRON.

You may be interested in the notes I use to set up my RPis which I've published here, including how to set up postfix. These notes do require some knowledge of *NIX. (I just noticed that the Markdown doesn't seem to be rendering quite right, but if you look at the plaintext/raw version it should be more legible.)

I am using the default pi account which I believe is the RPi equivalent to root.

pi is just a regular user, but on a normal Raspbian setup it has the ability to sudo without a password.

I set up a way to SSH onto the RPi before it gets installed in its new home

This is possible with configuring port forwarding on the router, but make sure to set up something like fail2ban as I describe in the link above.

Replies are listed 'Best First'.
Re^3: Continuous or timed?
by Bod (Parson) on Dec 14, 2020 at 16:28 UTC

    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>

      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". ;-)
      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.

      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 '.';?

Re^3: Continuous or timed?
by Bod (Parson) on Dec 14, 2020 at 23:51 UTC
    This (SSH) is possible with configuring port forwarding on the router, but make sure to set up something like fail2ban as I describe in the link above.

    I've set up a Real VNC account. The client comes pre installed on the Raspberry Pi and an account is free for home use. It's been tested using my mobile for one network and my home network for another and I can remotely access RPi without issue and without needing to change the router settings.