edelwater
edelwater

Reputation: 2802

Perl script works but not via CRON

I have a perl script (which syncs delicious to wp) which:

  1. runs via the shell but
  2. does not run via cron (and i dont get an error)

The only thing I can think of is that it read the config file wrongly but... it is defined via the full path (i think).

I read my config file as:

my $config = Config::Simple->import_from('/home/12345/data/scripts/delicious/wpds.ini',
   \my %config);

(I am hosted on mediatemple)

Does anybody have a clue?

update 1: HERE is the complete code: http://plugins.svn.wordpress.org/wordpress-23-compatible-wordpress-delicious-daily-synchronization-script/trunk/ (but I have added the path as above to the configuration file location as difference)

update 2: crossposted on https://forums.mediatemple.net/viewtopic.php?pid=31563#p31563

update 3: the full path did the trick, solved

Upvotes: 3

Views: 13581

Answers (6)

Trimbak Gopalghare
Trimbak Gopalghare

Reputation: 89

 If the perl script runs fine manually, but not from crontab, then
 there is some environment path needed by the some package that is not
 getting through `cron`. Run your command as follows:
 suppose your cron entry like:

* 13 * * * /usr/bin/perl /home/username/public_html/cron.pl >/dev/null 2>&1

 env - /home/username/public_html/cron.pl

 The output will show you the missing package. export that package path in
 $PATH variables

Upvotes: -1

Mike969
Mike969

Reputation: 51

I run into the same problem ...

Perl script works but not via CRON => error: "perl: command not found"

... after an update from Plesk 12.0 to Plesk 12.5. But the existing answers were not very helpful for me.

It took some time, but than I found this thread in the Odin forum which helps me: https://talk.plesk.com/threads/scheduled-tasks-always-fail.331821/

They suggest the following:

/usr/local/psa/bin/server_pref -u -crontab-secure-shell ""

That deletes in the /var/spool/cron/crontabs files the line:

SHELL="/opt/psa/bin/chrootsh"

After that, my cron jobs run with out any error.

(Ubuntu 14.04 with Plesk 12.5)

Upvotes: 0

Brad Clawsie
Brad Clawsie

Reputation: 1080

it seems the problem is not in running perl, but locating the Config library

you should try:

perl -e "print @INC"

and run a similar perl script in cron, and read the output

it possible that they differ

Upvotes: 4

Jonathan Leffler
Jonathan Leffler

Reputation: 753455

The difference between a cron job and a job run from the shell is 'environment'. The primary difference is that your profile and the like are not run for a cron job, so any environment variables you have set in your normal shell environment are not set the same in the cron environment - no extensions to PATH, no environment variables identifying where Delicious and/or WP are hosted, etc.

Suggestion: create a cron job that simply reports the environment to a known file:

env > /home/27632/tmp/env.27632

Then see what is set in your own shell environment in comparison. Chances are, that will reveal the trouble.

Failing that, other environmental differences are that a cron job has no terminal, and has /dev/null for input and output - so interactive stuff does not work well.

Upvotes: 7

Dave Jennings
Dave Jennings

Reputation: 316

Based on your crontab, and depending on your installation, the problem might be the "perl". As others note the environment, particularly the $PATH variable, is different for cron. perl may not be in the path so you need to put the full path to perl in the cron command.

You can determine the path with the command $ type perl

Upvotes: 1

mmccoo
mmccoo

Reputation: 8536

I suggest looking at my answer to How to simulate the environment cron executes a script with?

This is an similar Jonathan's answer but goes a bit further.

Upvotes: 2

Related Questions