resume timing in task scheduler? - windows

i am trying to make a program run for 13 hours every 7 days and then the program will stop and the task will end. However i may turn off my computer during that time and then do you know if when i start the task again the timer will resume?
for example
i start my task it runs for 5 hours i then turn off my computer.
next day i turn my computer on and the task starts and runs for 8 hours
then...
will the task end becasue it has reached 13 hours or will it continue to run till it reaches 13 hours?
is there a way to make the timer resume whenever i turn my computer off or do you know of any program that will do this
any help would be appreciated thanks

To some degree, it depends on the operating system your computer or mobile device runs. If you are running Windows 2000+ or a UNIX derivative (Linux, BSD, OSX), we have use of tools like cron to start us off. If it's a mobile device, we have a bit more work to do.
I'll assume you have a Windows or UNIX device to start. Therefore, you have the Startup/init.d layers of the OS to kick things off when you begin. This is used just to fire things off at power up. We might, for example, write a shell script/WSH script that, at login/startup, runs your up. At this point, you are running, but we want to do a bit more.
Since your app can now be started by the system, we need to make sure it stays running and is restarted if necessary, even if the system is not rebooted. For example, it could be killed/terminated by other events. Our goal is to start your script up at system start, and ensure it runs for 7 hours. Assuming UNIX/Linux:
This can be done with two tasks:
One task just ensures that we've run at least every seven days
The other task ensures when we run, we run for seven hours and no more.
Our first task is a pair of cron scripts. One runs ever 30 minutes. It's sole task is to check to ensure the main worker task is either running or finished. If it's not finished, and it's not running for some reason, start it. The second cron task runs every seven days and when run, cleans up the markers from the worker task.
Our main worker task, when run, splits its workload into 30 minute segments. It runs each segment, and leaves a "breadcrumb" in temporary storage somewhere -- basically, it says "I've done another 30 minutes of work". When it has 14 crumbs, it's done.
How this all works:
Cron or init.d starts up the main worker thread
THe worker thread runs, hopefully to 14 "chunks of work" and terminates.
Each week, the other cron tasks check to see if we had 14 chunks. If we did, it was a successful run. Remove them and start over. If not, restart the worker task.

Related

Windows Task Scheduler wont start task because it thinks previous version is still running

I have an occasional problem (maybe twice a month) were windows task scheduler won't start a new task because it thinks the old version is still running.
The task is a powershell script, it runs all day, every day. The task scheduler starts the script at 5 past midnight every day (UTC), and then the scripts exits itself everyday at 23:55 (UTC). The script does the following actions.
logs its own startup in a database
spends all day reading records from a remote server.
logs its own shutdown at 23:55 every night and exits with 'exit 0'
Task scheduler runs the script with the -NoExit option, so the powershell console remains open on the screen even after the task has exited (allowing a visual check of any output generated)
This all works fine 95% of the time, however, occasionally when the task scheduler attempts to start the new task at 00:05 I see the message 'Launch request ignored, instance already running' in the history. But when I check the log records from the powershell script I see that it started and finished at it's normal time, and I can double check this against the console.
Curiously, on these occasions the task scheduler history indicates that the blocking task finished at about 8am - a time which always corresponds to when I logged on that day.
Any suggestions on what's going wrong and how to sure it? I've already tried tweaking some of the task settings "if the task is already running then the following rule applies - stop the existing instance" but because the fault is intermittent, it's very hard to pin down.
Update - following further testing.
I've tried creating 100s of similar tasks and running them with similar conditions. So far I've reached two conclusions, firstly everything seems to work OK if I remove the -NoExit option. It's almost as if the scheduler has trouble differentiating between the command window, and the PowerShell script itself.
Secondly, everything seems to work ok if increase the gap between the previous schedule dying and the new one starting from about 15 minutes to half an hour or longer. It's as if the task scheduler takes time to work out that the old task has stopped.

Issue with windows tasks scheduler

I want to run powershell script every day and want to use task scheduler for it. But I have to be log in because this srcipt runs cisco vpn client and putty and then runs some python script for one minute. I don't want it to interrupt my work (because it swichs to different vpn etc.) so I set up time to run this task to 2:00 AM and check "run asap after a scheduled start is missed" to make sure that this task will run every morning after I turn on my computer.
But the problem is, that it doesn't run the script after turn on PC and it says event id 332 - Launch condition not met, user not logged-on. I think I understand this problem, it tries to run this script right after start up so at time I'm not log in. But why does not the task try it after 1 minute again up to 3 times? (see below)
What shoud I do to make sure that it will run every day after turn on PC but only once a day (sometimes I need to restart my PC so I don't want it to run again)
There is my task configuration:
Check the 'Run whether the user is logged on or not' and 'Run with highest privilege' options.it will work for you.

Scheduled task fails to run, no error code

We're using a scheduled task to run a simple executable every 2 minutes, it has a working directory set (no quotes round the path) but other than that most options are left as defaults.
Running the task manually by right-clicking on it and selecting Run works just fine, however it never executes automatically. When the time comes to run the task, it just increments the "Next Run Time" field by 2 minutes and that's it. The Last Run Time Field is always the last time the task was manually executed.
The Last Run Result is always 0x0.
I've tried setting it to run as the current user, or as an alternate user set up with administrative privileges and a stored password, but still no luck.
There doesn't appear to be anything immediately obvious in the system event log either to indicate the cause of the failure.
As a bit of background, this is a headless Win10 Pro machine (only ever accessed via LogMeIn) running control software for external hardware. It reboots every morning at 03:00 and since it's on an physically isolated network, automatically logs in to a user account with administrative privileges and no password.
I suspect it may be a permissions issue with the insecure way the system is set up, however at this point there's little to go on.
Any ideas?
Thanks
For posterity, this turned out to be an issue with the way the repetition on the scheduled task was set up. Initially it was set up as a daily task to run every 2 minutes for 24 hours. Whilst this showed the correct next run time in the task scheduler window, for some reason it never executed - Bug?
The fix was instead to set the task up as a one time event that repeats every 2 minutes indefinitely, which seems to be working properly now.

Issues of Jenkins build scheduling on Windows: delays in the execution of scheduled builds

My company installed Jenkins as a Windows Service on a VM with Windows 7 Professional. We scheduled 3 tasks for the night: one at 6.00, one at 6.10, one at 6.20. By looking at Jenkins logs, we saw that all the 3 tasks where delayed to around 7.20.
By looking at the Windows Event Viewer we discovered that the machine used to go to sleep mode after 30 minutes without activity (this is set in the Power Options of the Control Panel ).
Anyway, some windows scheduled task was waking up the machine (namely, some windows service for synchronizing the clock) every some time. By chance it was waking up at 7.20... As a consequence, also Jenkins was able to complete its tasks scheduled for one hour before.
Question: Do you know a better way to fix this other than disabling the "Put computer to sleep" option?
First - there is the obvious answer. Don't let the Jenkins server go to to sleep.
But there might be reasons for it. Personally, I have my own Jenkins server sleep during non-work hours. To get my server to wake up at the beginning of the day, I scheduled my own task in the Windows Scheduler that would wake the computer up 10 minutes before the first scheduled Jenkins task. The task could be anything, but the important part was flagging it to wake up the computer.
To go back to sleep at the end of the day, I have a Jenkins job that is set to trigger at the end of the day. The Job is a Windows Shell command "%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState Standby" that puts the Jenkins server back to sleep.

How to run a windows scheduled task 20 mins after system startup?

In windows scheduled tasks properties, you can only choose "at system startup" without being able to assign a specific delay such as 20 minutes, so I wonder how can I setup a schedule task if I want it to run after the system "fully" starts up(you know how fast this can be in XP)? Hope you guys know the answer. Thanks
Create a scheduled task to run an app you've written, have the app you've written sleep for 20 minutes and then run the original app.

Resources