snake
snake

Reputation: 752

running a perl script from a windows scheduled task

I have awstats installed on windows 2008 server. I schedule the Updatestats.bat file to run every day, the task runs fine without error, but the script is not being executed or is throwing an error that I cannot see.

-- If I run the bat file directly from command line then it works fine. --

I have tried various alternatives to the windows scheduler, such as "nncron" and "Freebyte Task Scheduler", nncron had the same issue, but the freebyte app worked, but sadly it does not run as a service so is of no use. here is the contents of the bat file, all lines look like this.

c:\strawberry\perl\bin\perl.exe D:\AWStats\wwwroot\cgi-bin\awstats.pl config=earlsmere.co.uk -update

anyone got any ideas ?

Upvotes: 0

Views: 6932

Answers (2)

Oleg V. Volkov
Oleg V. Volkov

Reputation: 22421

Your unattended environment is obviously different from you command line. Check if the following are set:

  1. Script's working directory, if it reads anything from it or uses relative paths.
  2. PERL*_LIB environment variables if your script uses any modules.
  3. PATH environment variable, if your script calls any external scripts/binaries.
  4. User that is running scheduled tasks have sufficient rights for everything you want to do.

As a quick workaround you can set them directly in script using chdir function, lib module, and $ENV{PATH} entry.

You also can try to capture standard output and error with following redirections before you start doing anything else:

open(STDOUT, '>>', '/full/path/to/out.log') || die "Error stdout: $!";
open(STDERR, '>>', '/full/path/to/err.log') || die "Error stderr: $!";

Note that you really should use full paths there in case you indeed have working directory set wrong. And make sure target directory/file is writable for anyone.

Upvotes: 1

Gonen
Gonen

Reputation: 4075

Looks like the output gets lost in space...

I suggest redirecting the output of the command to a file, like this:

c:\strawberry\perl\bin\perl.exe D:\AWStats\wwwroot\cgi-bin\awstats.pl config=earlsmere.co.uk -update > c:\my_log.txt 2>&1

(courtesy of Anders Lindahl: Redirect stdout and stderr to a single file in DOS)

Upvotes: 0

Related Questions