Discussion:
vbs scheduled task behaving very weird
(too old to reply)
Gabriela
2009-12-13 21:58:53 UTC
Permalink
Hi
I have a vbs file that crawls some webpages on the web.
It takes the vbs ~10hours to complete the run, and works just fine.
I want it to run daily every 2 hours.
I setup a scheduled task, that run daily, every 2 hours, and receives
param1 as input:
"wscript.exe MyScript.vbs param1"
-> My script ran only ONCE a day. I presume that this is probably
because scheduled task cannot instantiate a new vbs instance, while
the task's script is still running. True?
If so, than I setup 12 scheduled tasks - starting at 00:00, 02:00,
04:00, ...22:00 - under the assumption that since it takes ~10hours to
run, next scheduled task will be without 24 hours, and won't collide.
Now the vbs scripts are instantiated correctly every 2 hours BUT - a
weird thing is happening - it seems like all scripts currently running
finish at the exact same second, and are fully synchronized. They are
all at the same line of code, even though they began 2 hours later.
It's like they're waiting for each other to be synced, and start
together, and finish together.
What's up with that?
Thanks,
Gabi.
Pegasus [MVP]
2009-12-13 22:23:21 UTC
Permalink
Post by Gabriela
Hi
I have a vbs file that crawls some webpages on the web.
It takes the vbs ~10hours to complete the run, and works just fine.
I want it to run daily every 2 hours.
I setup a scheduled task, that run daily, every 2 hours, and receives
"wscript.exe MyScript.vbs param1"
-> My script ran only ONCE a day. I presume that this is probably
because scheduled task cannot instantiate a new vbs instance, while
the task's script is still running. True?
If so, than I setup 12 scheduled tasks - starting at 00:00, 02:00,
04:00, ...22:00 - under the assumption that since it takes ~10hours to
run, next scheduled task will be without 24 hours, and won't collide.
Now the vbs scripts are instantiated correctly every 2 hours BUT - a
weird thing is happening - it seems like all scripts currently running
finish at the exact same second, and are fully synchronized. They are
all at the same line of code, even though they began 2 hours later.
It's like they're waiting for each other to be synced, and start
together, and finish together.
What's up with that?
Thanks,
Gabi.
I would start by adding some simple diagnostics to each script, e.g. like
so:
- Instead of using a single script, use 12 of them, each starting with this
statement:
const sVersion = "Script02" (or "Script 04") etc.
- Each time a script starts, get it to add a log line to its own log file
c:\Script02.log. Make it something like
oLogFile.writeline "Script started", now()
- Do the same when the script ends.

When you examine the log files then you will know exactly when each script
started and ended. Two more points:
- AFAIK you can run several instances of cscript.exe at the same time.
- Rather than running 12 tasks, run a single task and repeat it once every
two hours. Remember to make its duration 24 hours! (This is for the
production run, not for the above test).
- You shoul also examine the Task Scheduler log file. What does it report?
Gabriela
2009-12-14 08:11:53 UTC
Permalink
Hi Pegasus,
Thanks for the tips.
I really wanted to avoid multiplying the script 12 times, as you
suggested. But if there's no other way - I'll do it.
I did start with having a single scheduled task, running every 2
hours, for 24 hours - but it ran only once.
When I changed the vbs script (just for testing) - to last for several
minutes, not 10 hours - it did ran every 2 hours.
It seems to me that the script does not instantiate itself when it is
already on-air.
More important - since I'm working with FTP on the server - is there a
script that creates/modified/deletes the scheduled tasks, and not
through the control panel scheduled task GUI?
Where can I see the Task Scheduler log file?

Thanks,
Gabi
Pegasus [MVP]
2009-12-14 10:37:38 UTC
Permalink
You can see the Task Scheduler log file in the Control Panel / Task
Scheduler under the Advanced pull-down menu.

Your problem is not that the script fails to re-instantiate itself when it
is already running. It is that the Task Scheduler won't relaunch a task that
is still active. If you do want your tasks to run concurrently the you must
create separate tasks for them.

Since different operating systems have different Task Schedulers, it would
help if you stated your server version.
Post by Gabriela
Hi Pegasus,
Thanks for the tips.
I really wanted to avoid multiplying the script 12 times, as you
suggested. But if there's no other way - I'll do it.
I did start with having a single scheduled task, running every 2
hours, for 24 hours - but it ran only once.
When I changed the vbs script (just for testing) - to last for several
minutes, not 10 hours - it did ran every 2 hours.
It seems to me that the script does not instantiate itself when it is
already on-air.
More important - since I'm working with FTP on the server - is there a
script that creates/modified/deletes the scheduled tasks, and not
through the control panel scheduled task GUI?
Where can I see the Task Scheduler log file?
Thanks,
Gabi
Gabriela
2009-12-14 11:19:04 UTC
Permalink
Thanks.
The server is Windows 2003 Server.
That's why I changed it from single task, scheduled to every 2 hours,
for 24hours - to 12 separate tasks, running the same vbs, scheduled
for 00:00.02:00,04:00...22:00.
But all 12 scripts run very weird together - as I wrote above, it's
like they are synchronizing themselves to run together.
If I manually run the scripts (by double clicking the vbs) at
different hours - all works fine - each script runs for ~10hours.
From scheduled task - they start at 2 hours difference, but finish the
run at the same second...
If there's no other option - I will duplicate the vbs scripts.
Pegasus [MVP]
2009-12-14 11:46:53 UTC
Permalink
Post by Gabriela
Thanks.
The server is Windows 2003 Server.
That's why I changed it from single task, scheduled to every 2 hours,
for 24hours - to 12 separate tasks, running the same vbs, scheduled
for 00:00.02:00,04:00...22:00.
But all 12 scripts run very weird together - as I wrote above, it's
like they are synchronizing themselves to run together.
If I manually run the scripts (by double clicking the vbs) at
different hours - all works fine - each script runs for ~10hours.
From scheduled task - they start at 2 hours difference, but finish the
run at the same second...
If there's no other option - I will duplicate the vbs scripts.
If you want to run your scripts concurrently then you need to duplicate the
tasks, not the scripts.

Loading...