Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl cgi script called from Cron

Status
Not open for further replies.

jez

Programmer
Apr 24, 2001
370
VN
Hi,

I am trying to automate a script that needs to run every other night.

When i run it from the command line:- perl limey.cgi from within the httpdocs folder of linux webserver, all is runs fine.

Then in the cron tab i have the following entry

23 1 */2 * * /var/www/vhosts/[DOMAIN NAME]/httpdocs/limey.cgi 2>&1 >> /var/www/vhosts/[DOMAIN NAME]/logs/limey.log

This is all pretty standard stuff.

Unfortunately it seems when it runs it fails to find perl modules that are included with the 'use' keyword.

The one it fails on is ;-

use lib '../lib/perl5';

This is to add some additional modules.

It seems that the relative path is causing a problem here.

Can anyone tell me the best way to run a perl cgi script that is in the public part of the website from a cron job.


Thanks very much.

Jez
 
Just put in the full path instead of ..
You can not rely on relative paths on scripts being called from cron. Nor can you rely on user environment variables. You should always provide the full path to everything.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
If you have your heart set on using relative dirs in your include statement, you can use this work around to make it work more universally. This makes it so that that the current directory is assumed to be the one where the script is located instead of where the script is called from.

Code:
[gray][i]# use lib <perl Directory>[/i][/gray]
[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]lib[/green][red];[/red]
[black][b]use[/b][/black] [green]Cwd[/green] [red]qw([/red][purple]abs_path[/purple][red])[/red][red];[/red]
[black][b]use[/b][/black] [green]File::Basename[/green] [red]qw([/red][purple]dirname[/purple][red])[/red][red];[/red]
[olive][b]BEGIN[/b][/olive] [red]{[/red]
	[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$local_dir[/blue]= [maroon]dirname[/maroon][red]([/red]__FILE__[red])[/red][red];[/red]
	[black][b]my[/b][/black] [blue]$inc_dir[/blue] = [maroon]abs_path[/maroon][red]([/red][red]"[/red][purple][blue]$local_dir[/blue]/../lib/perl5[/purple][red]"[/red][red])[/red][red];[/red]

	lib->[maroon]import[/maroon][red]([/red][blue]$inc_dir[/blue][red])[/red][red];[/red]
[red]}[/red]
[tt]------------------------------------------------------------
Pragmas (perl 5.10.0) used :
[ul]
[li]lib - Manipulate @INC at compile time[/li]
[/ul]
Core (perl 5.10.0) Modules used :
[ul]
[li]Cwd - get pathname of current working directory[/li]
[li]File::Basename - Parse file paths into directory, filename and suffix.[/li]
[/ul]
[/tt]

- Miller
 
Thanks, I will give that a try. Full paths are currently givinge errors with the use statements so I guess I have to edit all the paths in the script too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top