running a perl script from a windows scheduled task - windows

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 ?

Your unattended environment is obviously different from you command line. Check if the following are set:
Script's working directory, if it reads anything from it or uses relative paths.
PERL*_LIB environment variables if your script uses any modules.
PATH environment variable, if your script calls any external scripts/binaries.
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.

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)

Related

Powershell Script converted to EXE via Win-PS2EXE can be run manually but errors out when run as a scheduled task

The application moves files from one directory to another, runs an exe, and then moves files from one directory to another.
When I run the application manually it works as expected.
However, when trying to run it as a scheduled task I get the following error: 3762504530
I did some researching and it appears it may have to do with the application trying to run interactively even when there is no user actually logged in.
I have tried to suppress outputs but that didn't seem to have any effect.
Without seeing the code i guess u use console output or similar...
If so change write-host to write-output or alias "echo" pipe it to log file if u want...
Also be sure that your script run "non interactive" (no prompts etc.)
Unchecking compile a graphic windows program (parameter -noConsole), remedied the error.

Using redirects inside a batch file

This seems like I'm missing something obvious but I can't get redirects (>) to work in a .bat / .cmd file.
From the command line, this works as expected and sends the output and error streams to the log file:
doxygen doxygen.config 2>&1 > doxygen.log
Putting the exact same line inside a batch file and running it doesn't work however. It looks like it tries to write the entire command to the log file rather than execute it and then loops??
How do I get output redirects to work inside a bat / cmd file? In case it makes a difference, I am using Win7 and have tried from cmd and powershell.
Perhaps the batch script is calling itself. I would suggest you explicitly specify the extension for the executable your script is calling:
doxygen.exe doxygen.config 2>&1 > doxygen.log

Windows, ClearCase, and Ant: how to handle directory slashes?

I have a Windows batch script that I use to build a module and the script in turn uses the ClearCase clearmake command to drive the actual compilations, directory creations and file manipulations, i.e. process the Makefile content. The batch script works flawlessly when invoked using a DOS window or from a "cmd /c ..." command line invocation. And it has been that way for some number of years.
I recently decided to move the script to Ant. The first step, out of simplicity, was to simply invoke the script unchanged using an Exec task (using cmd /c). Almost immediately, Ant fails while creating a directory. The error message reports something like:
mkdir: Cannot create the directory C:\\fred\\harry\\joe
I was able to verify that, using the DOS command prompt, the mkdir C:\\fred\\harry\\joe command works fine, so, as near as I can tell so far, Ant generating double backslash path separators combined with something inherent to clearmake and/or something in the Makefile is causing the failure.
The response I'm looking for is something along the lines: "Yes, clearmake is definitely the culprit because..." or "If you twiddle this thing or that thing in Ant, only a single backslash will be generated...". Should there be no simple and quick explanation, I will drill into the problem to determine what exactly is causing the failure.
Thanks,
I have seen similar error with:
dynamic views (more sensible to ownership than a snapshot view on C:\, which is your case)
resource handle conflict (the script tries to update a resource already taken by another process, which shouldn't be the case here with your script, since it was working outside of Ant Exec task)
error message (like you create a directory which already exists: the error get ignored in a classic script, while it could interrupt the ant task.
While the last cause is a good candidate, try first to simplify your script (leave only the mkdir for instance) in order to check that this line is indeed the issue (nd not "this line in conjunction with others actions taking place just before")

run windows command from bash with output to standard out?

Folks, I'm using git tools such as git bisect run which need to call a command to build and test my project. My command to do is nant which is a windows program. Or a build.cmd script which calls nant.
It's easy to get the bash to call the nant build to run.
But the hard part is how to get the standard output written to a file?
I even installed the Windows PowerShell to try running a command from bash.
Again, it works but the standard output fill says "permission denied" when
I try to read it while the build is going on.
Update:
When running nant, the entire path is used. It is installed and runs fine. The problem is how to get the standard output when running from bash.
If running nant from the windows prompt with "> build.out" at the end of the line, you will get the standard out. But the same never works under bash. It just says build.out is locked, permissions denied.
Update:
Using tee as suggested below also doesn't solve the problem. In that case the file still report "access is denied" with any attempts to read it while the build runs. But also, the tee program never writes anything to standard output.
(If I am understanding your question correctly...)
You can probably use the 'tee' command to split the output to both a file and stdout. The line echo I am building something | tee build.out will both print the output on the console and save it to the file named "build.out".
The tee command is usually available in Cygwin, and also apparently in the Bash shell installed by msysgit (where I just tested it). Here's a good reference page for more details.
Okay, finally resolved this. It turns out the the nant build script was using git feature to erase all ignored files to cleanup. That was deleting the build.out file can causing these strange issues. Now, the process writes the build.out file to a parent directory so that it won't get deleted and now everything works smoothly as expected.

Opening a Web URL with a TCL App that is Sitting on a Network Drive

I just finished a TCL Db App that includes a featrue to open web page URLs. My code is as follows ($adr is the url):
eval exec [auto_execok start] \"\" [list $adr]
This code works fine on my Windows workstation. However, after I placed the app on a network drive I receive the following error:
'\Drive\Share\Folder\Subfolder'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
The web page still opens, but I still get the TCl error.
Does soemone know a better way to open URLs with TCL in a server or network environment?
Thank you,
DFM
The message displayed is actually being generated by CMD.EXE, the Windows command interpreter, when Tcl tries to execute the URL that you specify. It generates that warning message to stderr when it is started with a current working directory that is set to a network path.
Two other things you could have tried:
run exec with -ignorestderr. This will cause this particular warning message (and any other messages/errors written to stderr to not produce an error in Tcl). When you wrap your code with catch, you are basically ignoring this and any other errors, which may not be ideal.
eval exec -ignorestderr [auto_execok start] \"\" [list $adr]
set your working directory to another path prior to the exec, which is what CMD.EXE is doing after it prints out that warning:
cd $::env(TEMP)
eval exec [auto_execok start] \"\" [list $adr]
Of course, be careful about running arbitrary commands and arguments that come from untrusted inputs, or someone might use your application as a backdoor to run malicious commands.

Resources