Correct. It also doesn't run the .bashrc and stuff. For this reason, i usually have cron call a bash script that THEN starts the perl script in question. Excerpt from my user crontab:

20 1 * * * /bin/bash /home/cavac/src/pagecamel_cavac/devscripts/geoip/updategeoip.sh >> /home/cavac/src/pagecamel_cavac/devscripts/geoip/crontab.log 2>&1 &

Note that this specifies the FULL path to the script. It also rereoute all STDOUT and STDERR into a logfile. Here's the script:

#!/usr/bin/env bash . ~/.bashrc_cavac cd /home/cavac/src/pagecamel_cavac/devscripts/geoip date perl updategeoip.pl

What this does is source the bashrc script that sets all the proper environments, change directory to the one the perl script expects, runs date (so the logfile contains a line with the timestamp of the run) and then runs the perl code.

Just for reference, here's the bashrc-script. I removed parts that are not relevant for this answer; it actually does a lot more, depending on which system and for which user it's running:

# CavacPerl export PATH=/home/cavac/bin/CavacPerl-5.36.1/bin:$PATH export MANPATH=/home/cavac/bin/CavacPerl-5.36.1/man:$MANPATH # Scripts export PATH=/home/cavac/bin/scripts:$PATH toilet -f smblock --filter metal:border virgo.cavac.at

(The "toilet" command runs on every computer/account of mine that allows ssh login, to show a banner of the system i logged in. Mostly to prevent me debugging on the wrong machine and wondering why it doesn't work.)

As a side note, running bash scripts to run your perl code also allows you to make sure you are running the most recent version of the script. On some of my raspberries is just run the appropriate mercurial SCM commands before running the perl script. Another win for total laziness, now i don't even have to update those ancient things manually...

PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP

In reply to Re^2: use lib "." by cavac
in thread use lib "." 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.