Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Continuous or timed?

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


in reply to Continuous or timed?

The consensus and my gut feeling both suggested 2 so that is the option I have settled on...

The control software is working - it needs more development but I am up against a time restriction as Christmas is coming and this controller is supposed to be a Christmas gift! I'm using only code modules as installing anything from CPAN seems to fail but this can be addressed later provided I set up a way to SSH onto the RPi before it gets installed in its new home.

The problem I have hit is with CRON.

The first few lines of the script are:

#!usr/bin/perl use lib '.'; use Curtains::Control; use Bod::Config; use strict;
But, despite the shebang line, it won't run simply by calling curtains.pl it needs perl curtains.pl instead. Perl is definitely installed in /usr/bin/perl and I also get this:
pi@eric:~ $ /home/pi/Curtains/curtains.pl -bash: /home/pi/Curtains/curtains.pl: usr/bin/perl: bad interpreter: N +o such file or directory
So I suspect I have something wrong in this setup.

Within the crontab I have added:

MAILTO=ian@****.com */2 * * * * perl /home/pi/Curtains/curtains.pl
but I am not getting emails with any errors from CRON.

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

Replies are listed 'Best First'.
Re^2: Continuous or timed?
by haukex (Archbishop) on Dec 14, 2020 at 14:26 UTC
    #!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.

      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?

      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.

Re^2: Continuous or timed?
by choroba (Cardinal) on Dec 14, 2020 at 14:26 UTC
    #!/usr/bin/perl ^ | The leading slash isn't optional

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re^2: Continuous or timed?
by stevieb (Canon) on Dec 14, 2020 at 16:28 UTC
    "I am using the default pi account which I believe is the RPi equivalent to root."

    That's an incorrect assumption.

    Raspbian, the OS of the Raspberry Pi, which is Linux, creates the pi user account, and it's the default standard user. root is the super user account. You execute commands as root using sudo. It's highly unlikely that with what you're doing, you need super user access. Don't use super user access except when absolutely necessary, and use the super user account for as short a duration as possible.

      Do I need to change the password of root to prevent malicious access as the device will be, and currently is, connected to the internet or is it inaccessible anyway?

      I guess not as I haven't been prompted like I was with pi

        The root user in Raspbian has no password; therefore it is inherently secure. Clear as mud, eh? ;)

        It's set up in a special way so that A) the root user has no login access and is only available via sudo, and B) so long as your pi user has a good password (or SSH key access only), then you're golden, as the pi user is by default the only user allowed to sudo.

        If you set a root password, then you've opened up an attack vector, as the root user will then have login access.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found