running a perl script from a scheduled task
-
Sunday, June 03, 2012 3:45 PM
I am running awstats and need to run a batch file that updates all the stats on a scheduled task.
the contents of the bat file look like this
c:\strawberry\perl\bin\perl.exe D:\AWStats\wwwroot\cgi-bin\awstats.pl config=mydomain.co.uk -update
This works just fine when I run it from CMD prompt, but when I run it from a scheduled task the perl doesn't get executed. The task itself is definitely being executed and there are no permission issues.
I have tried a a couple of cronjob managers for windows, and the above executes just fine with those, so it is definitely and issue with the windows task scheduler.
anyone got any ideas ?
Russ Michaels
All Replies
-
Sunday, June 03, 2012 4:18 PM
Hello,
I recommend you check schedule task setting once again.Please go through this article http://technet.microsoft.com/en-us/library/dd851678.aspx
Regards, Ravikumar P
-
Sunday, June 03, 2012 5:15 PM
Try changing the batchscript syntax to the following :
start /Dc:\strawberry\perl\bin perl.exe D:\AWStats\wwwroot\cgi-bin\awstats.pl config=mydomain.co.uk -update
To be honest I can't remember the details of why that works and why yours doesn't (might be the difference in user context between starting manually and via scheduled tasks), but that's the method I found years ago to initiate some perl scripts (MRTG in my case) via scheduled tasks, and they've been running ever since.
-
Monday, June 04, 2012 5:35 AMModerator
Hi,
What is your OS version? Which user account do you use to run the script in scheduled task?
Have you find any error log related to scheduled task?
> This works just fine when I run it from CMD prompt, but when I run it from a scheduled task the perl
> doesn't get executed. The task itself is definitely being executed and there are no permission issues.So you mean you can’t even run scheduled task manually?
You modify Start in text box to the same you run the command in CMD prompt. Start in text box specifies the working directory for the command line that executes the program or script. This should be either the path to the program or script file or the path to the files that are used by the executable file.
There are lots of settings in scheduled task configuration, it’ll very useful for troubleshooting if you can post screen capture for each settings tab.
For more information please refer to following MS articles:
Scheduled task won't run .bat file
http://social.technet.microsoft.com/Forums/en-US/winservermanager/thread/d47d116e-10b9-44f0-9a30-7406c86c2fbe
A scheduled task does not run as expected if a command-line argument is enclosed in quotation marks on a computer that is running Windows Server 2008 or Windows Vista SP1
http://support.microsoft.com/kb/951246
Windows Vista onwards scheduled tasks fail to run if the path in "Start in (Optional)" field has quotes
http://support.microsoft.com/kb/2452723Hope this helps!
If you areTechNet Subscription user and have any feedback on our support quality, please send your feedback here.
Lawrence
TechNet Community Support
- Marked As Answer by Lawrence LvMicrosoft Contingent Staff, Moderator Thursday, June 14, 2012 1:22 AM
-
Monday, June 04, 2012 9:56 PM
sorry Keith no dice. Although this did change the last run result to "(0x0)".
Russ Michaels
-
Monday, June 04, 2012 10:07 PMWhat was the result before then? If it wasn't 0x0 (eg success) then there must have been something else happening, though you said the task was executing correctly. It's possible there were actually two issues, so the scheduled task side of things has now been resolved, and something else isn't working now. Since the scheduled task is now definitely running, the next thing I'd try is running it via scheduled tasks while you have Process Monitor (http://technet.microsoft.com/en-us/sysinternals/bb896645) running, just to check it's not having any issues with permissions, file paths etc that would stop it from running correctly.
-
Monday, June 04, 2012 10:11 PMnormally is says (0x1) but there are no errors and the history says the task executed successfully.
Russ Michaels
-
Monday, June 04, 2012 10:15 PM
Lawrence, i'm runnng windows 2008 r2
yes I can run the task manually, still not executing that bat though
I have set the "start in" value to the folder with the bat file
I have gone through the links you provided and checked my settings and tried explicitly setting the permissions as suggested, it did not help.
here are my settings.
http://screencast.com/t/56hPzo7sPERuss Michaels
-
Tuesday, June 05, 2012 8:11 AMModerator
Hi,
The settings looks correct, but I found you set to run the scheduled task use “scheduler” account, not the user your create the scheduled task (Administrator).
So what’s the security context your run command in CMD prompt?
Can you run the .bat script directly in your security context, and whether it updates stats?
Press “Shift” key then right click that .bat script, select run as different user, use “scheduler” credential to run the script, and check whether it updates stats?
Since that scheduled task executed successfully, I think the reason is “scheduler” user don’t have permission to update stats configuration.
Please test that and give us feedback for further troubleshooting.
Hope this helps!
If you areTechNet Subscription user and have any feedback on our support quality, please send your feedback here.
Lawrence
TechNet Community Support
-
Tuesday, June 05, 2012 10:00 AMI tried running the scheduled task as "administrator" which is who I am logged in as and created the task as, and that still didn't work.
Snake
-
Wednesday, June 06, 2012 9:31 AMModerator
Hi,
> I tried running the scheduled task as "administrator" which is who I am logged in as and created the task
> as, and that still didn't work.Do you mean you can’t even run that script successfully?
After search I found some related threads that record similar issue:
Windows 2008 Task Scheduler
http://social.technet.microsoft.com/forums/en-us/winservergen/thread/A3C25ED2-19DE-4707-9B4E-D577A2CA23B8
Problems running a batch script in virtual server
http://social.technet.microsoft.com/Forums/en-US/winserverhyperv/thread/ffdc089d-6ae9-4a5d-bcce-6a2043afa91aI’m not familiar with perl.exe, I think whether we can output perl.exe command process log:
c:\strawberry\perl\bin\perl.exe D:\AWStats\wwwroot\cgi-bin\awstats.pl -config=mydomain.co.uk –update -output > log.html
For more information please refer to following link:
Install Awstats on your home PC – Tutorial
http://www.lunarforums.com/web_hosting_tutorials_faqs_and_resources/install_awstats_on_your_home_pc_tutorial-t18084.20.html;wap2=And we recommend you create a thread and post it in The Official Scripting Guys Forum! Which is a best resource for scripting related issues.
The Official Scripting Guys Forum!
http://social.technet.microsoft.com/Forums/en/ITCG/threads
Hope this helps!
If you areTechNet Subscription user and have any feedback on our support quality, please send your feedback here.
Lawrence
TechNet Community Support
- Marked As Answer by Lawrence LvMicrosoft Contingent Staff, Moderator Thursday, June 14, 2012 1:22 AM
-
Monday, June 11, 2012 1:46 AMModerator
-
Thursday, June 14, 2012 1:22 AMModerator
Hi,
As this thread has been quiet for a while, we assume that the issue has been resolved. At this time, we will mark
it as ‘Answered’ as the previous steps should be helpful for many similar scenarios.If the issue still persists and you want to return to this question, please reply this post directly so we will be
notified to follow it up. You can also choose to unmark the answer as you wish.In addition, we’d love to hear your feedback about the solution. By sharing your experience you can help other
community members facing similar problems.Thanks!
Lawrence
TechNet Community Support
-
Thursday, June 14, 2012 1:28 AM
Hi yes, it does seem to be solved.
it seems I had solved it earlier than I thought, but the script was no longer generating any new output as there were no new logs to import, as this was just a test site i setup for the purpose of getting the script working. So several days later there were no new hits on the site, thus no new logs to import, so the perl script wasn't actually doing anything new.
So i'm not really sure at what point I fixed it now.. LOL
Snake

