in reply to use lib "."
What am I overlooking here?
You are overlooking what the current directory is when running the cron script. Set up a trivial cron job which just prints the current working directory and then you will know. It's usually $HOME unless you change it.
There are, as usual, so many ways to tackle this. My usual approach is to have cron run a shell script which does all the set-up (change to the right directory, populate the environment etc.) and then at the last have that script exec the perl script. I've found this to be robust and secure (in that it doesn't leak any info). You can have the same shell script (or 2 copies of the same script) for both test and prod and just pass it a different argument to choose which path to run. eg:
#!/bin/bash if [ "$1" == 'prod' ]; then cd $HOME/website/prod else cd $HOME/website/test fi export DOCUMENT_ROOT=./www exec ./lib/maintain.pl
And in your crontab call it like
30 5 * * * $HOME/website/prod/maintain.sh prod
I do find it slightly odd that you have scripts in your lib dir. I tend to keep all my cron jobs in a cron dir for clarity.
🦛
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: use lib "."
by Bod (Parson) on Aug 12, 2023 at 19:11 UTC | |
by hippo (Archbishop) on Aug 12, 2023 at 22:55 UTC | |
by Bod (Parson) on Aug 13, 2023 at 09:50 UTC | |
by parv (Parson) on Aug 13, 2023 at 10:11 UTC |