Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am running a perl script in crontab as follows:
* * * * * /home/httpd/vhosts/mysite.com/cgi-bin/deleteFiles.pl?docume +ntroot=/home/user/directory

However , this file doesn't run at every minute .
So I tried
* * * * * /home/httpd/vhosts/mysite.com/cgi-bin/deleteFiles.pl /home/ +user/directory

i.e passing the path as a argument .
But the perl file didn't ran in both cases .
My perl file code for first few lines where I tried above is as follows :
#!/usr/bin/perl use CGI; use DBI; my $query=new CGI; print $ARGV[0]; my $documentroot=$query->param("documentroot"); print $documentroot; exit 1;

For the time being I am trying to print the path so that I know that the script gets the path properly .
Can anyone let me know wht wrong I am doing in my script or cron settings .
Thankyou for paying attention to my question.

Replies are listed 'Best First'.
Re: Running Perl Script from Crontab
by Corion (Patriarch) on Apr 13, 2004 at 16:17 UTC

    One thing that you must test before running a script via cron is, whether it runs from the command line.

    Your script does not run via the command line, because the shell does not pass parameters like CGI does.

    So I can only recommend to remove all the CGI crap, to take the script out of the document root, and to run it like a normal script. You might also need to make the script executable (with chmod) and check that perl is actually at /usr/bin/perl, as referenced by your #!-line.

Re: Running Perl Script from Crontab
by Plankton (Vicar) on Apr 13, 2004 at 16:18 UTC
    The crontab entry ...
    * * * * * /home/httpd/vhosts/mysite.com/cgi-bin/deleteFiles.pl?documen +troot=/home/user/directory
    ... could of been writen like so ...
    * * * * * wget http://mysite.com/cgi-bin/deleteFiles.pl?documentroot=/ +home/user/directory
    The crontab entry ...
    * * * * * /home/httpd/vhosts/mysite.com/cgi-bin/deleteFiles.pl /home/u +ser/directory
    ... could of been writen like so ...
    * * * * * /home/httpd/vhosts/mysite.com/cgi-bin/deleteFiles.pl documen +troot=/home/user/directory
    Your print debug statement should look like this ...
    print "doc=[$documentroot]\n";

    Plankton: 1% Evil, 99% Hot Gas.
Re: Running Perl Script from Crontab
by blue_cowdawg (Monsignor) on Apr 13, 2004 at 16:20 UTC

    First thing I see is you are instantiating CGI and it is probably waiting for input from stdin.

    Since you are running this from cron and you are not redirecting anything into stdin for the script it is probably hanging. Just a guess...

    Are you seeing any error spew from cron?

Re: Running Perl Script from Crontab
by ambrus (Abbot) on Apr 13, 2004 at 17:11 UTC

    Is the script has execute permission by whatever uid cron tries to run it? Is the she-bang line correct?

Re: Running Perl Script from Crontab
by runrig (Abbot) on Apr 13, 2004 at 20:08 UTC
    You're printing from cron? Where do you expect the output to go? At the least I'd put on some redirects on the end of the crontab line, e.g., '>>/tmp/some_file 2>&1'

    Update: Duh...forgot about that :( (I would still redirect to a file though :)

      Where do you expect the output to go?
      email inbox
Re: Running Perl Script from Crontab
by ParseException (Novice) on Apr 13, 2004 at 19:25 UTC
    I think its your cron entry, it looks like it's never executing, try something like this:
    */1 * * * * /home/httpd/vhosts/mysite.com/cgi-bin/deleteFiles.pl?docume +ntroot=/home/user/directory