Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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
add comment

2 Answers

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

share|improve this answer
    
I might need some help making said shell script, ramruma. My attempt (above) didn't work. –  harvest316 May 27 '12 at 10:46
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.