Agreed on all counts.

Here's an example crontab entry I've got on some of my Pi CI systems where I start a test listener program at reboot. It logs all the output to a dedicated file:

@reboot /path/to/perl /path/to/bbtester start > /tmp/cron_bbtester.log + 2>&1

Regarding the use lib problem, there is a solution to allow the finding of libs regardless of where one runs the script from. Here's a simple module, that is located in the same directory the script is in (~/scratch/demo for this example):

package Module; use warnings; use strict; use Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(flail_around); sub flail_around { print "Flailing like a dying chicken!\n"; }

Here's the script. Note the use of $RealBin. That variable contains the directory where the script resides. It's equivalent to ., if one is actually within that directory:

use warnings; use strict; use FindBin qw($RealBin); use lib $RealBin; use Module qw(flail_around); flail_around();

Output when I run the script from within that dir:

spek@scelia ~/scratch/demo $ perl script.pl Flailing like a dying chicken!

Output if I run the script from somewhere else within the file system:

spek@scelia ~ $ perl scratch/demo/script.pl Flailing like a dying chicken!

So it's very similar to use lib '.', but it uses the absolute path which is generated on the fly by looking up which directory the script is actually in. If your modules were in a lib/ dir within the directory, change use lib $RealBin; to use lib "$RealBin/lib";.


In reply to Re^7: Continuous or timed? by stevieb
in thread Continuous or timed? by Bod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.