Cron – How to call perl from crontab

cronperlshared-hostingshell-scripting

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.

Best Answer

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

Related Topic