1

I can run this command fine from the SSH console of my rackservers shared hosting:

cd /home/myaccount/public_html/whatever; perl -w 
-I/home/myaccount/public_html/whatever rss2txt.pl http://whatever.com/feed

But when I enter the same command as a cron job, I get:

Can't locate XML/RSS.pm in @INC (@INC contains: /home/myaccount/public_html/whatever /usr/local/lib/perl5/5.8.8/x86_64-linux /usr/local/lib/perl5/5.8.8 /usr/local/lib/perl5/site_perl/5.8.8/x86_64-linux /usr/local/lib/perl5/site_perl/5.8.8 /usr/local/lib/perl5/site_perl . .) at rss2txt.pl line 21. BEGIN failed--compilation aborted at rss2txt.pl line 21.

Despite the fact that RSS.pm is sitting right next to it in the same directory (/home/myaccount/public_html/whatever), and it's got that path in the @INC, and I've done a cd to the correct folder just in case, it still whinges.

Bearing in mind it's on shared hosting so I can't change global settings, how can I convince perl to look for RSS.pm in /home/myaccount/public_html/whatever ?

Not sure it's relevant, but here's rss2txt.pl: http://pastebin.com/GWKZtJCN

ramruma suggested turning this into a shell script (below). I include my attempt here because comments can't be multiline:

#!/bin/bash
PERL5LIB=$HOME/public_html/whatever
PATH=$PATH;$HOME/public_html/whatever
cd $HOME/public_html/whatever
perl -w -I$HOME/public_html/whatever rss2txt.pl http://whatever.com/feed

Despite adding the folder to PERL5LIB, PATH, and @INC, this shell script doesn't even work from the SSH console. So if we can get this shell script working, I reckon we'll have the problem solved.

harvest316
  • 115
  • 8
  • While the mechanics of bash appear to be eluding me today, I don't think that's the crux of the issue. As you can see in the error message, we're already succeeding at getting the path in @INC. Why then isn't it picking it up? – harvest316 May 27 '12 at 11:05
  • News flash: `perl -MXML::RSS -e'print $XML::RSS::VERSION'` works fine from the console, where @INC doesnt have `$HOME/public_html/whatever` folder in it. So maybe it's nothing at all to do with include paths. – harvest316 May 27 '12 at 11:20
  • The ; in PATH should be a : and is perl really in /usr/local/bin as at the top of rss2txt.pl? – ramruma May 27 '12 at 12:16

2 Answers2

4

Write a shellscript that runs the command after setting any appropriate environment variables.

ramruma
  • 2,740
  • 1
  • 15
  • 8
4

you can add the local dir to the PERL5LIB environment variable at the top of your cron script like so;

PERL5LIB=/home/myaccount/public_html/whatever:.
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

52 * * * *  /usr/bin/perl -w -I/home/myaccount/public_html/whatever/rss2txt.pl http://whatever.com/feed
Tom
  • 11,176
  • 5
  • 41
  • 63