download only from 1am - 8am (ruby) - ruby

I have a script running on windows box that downloads files from the net via http. I want it to download only from 1am - 8am (my ISP's off peak time). I am happy if already started download finishes after 8am but what is the best method to make sure that the script starts downloading after 1am? I want to run the script and go to sleep. I want to use ruby only.
Is sleep the best way how to do it?

There is a good article on this here: Scheduling tasks in Ruby / Rails
But as someone else mentioned, you should use the windows task scheduler to start your script. Unless you really want to start it manually at 1am and every time you reboot your windows box... See this other SO question on how to add a scheduled task using the AT DOS command: What is the Windows version of cron?

Related

Schedule script on windows so that it should always be running in background when someone logins

I am a beginner at developing Windows apps. I have created a VB script that executes the EXE file in background. I have referred some articles online and scheduled the script with windows scheduler. Now Every time I log in to the computer, the script starts running in the background normally as expected. The problem occurs when I lock the computer for a long period of time, somehow script gets killed by Windows. If I try to log in again, script(which got killed) doesn't start once again.
I want the script to run every time the computer gets unlocked no matter whether the computer was restarted/power-on/woke up from sleep and it should start running the script. But I am unable to achieve this.
This is what my current trigger looks like . Please tell me if I am doing something wrong

Powershell: how to pause or delay or block shutdown to give time for cleanup tasks?

I have a powershell script that is running all the time on windows 7. If user does computer shutdown or reboot, I need a little time to do cleanup tasks such as updating log file.
Is there a way to delay shutdown from within script?
Solutions I've found from searching don't work well:
*Listening for events such as SessionEnding are too late and powershell is closed before script has time to do anything
*I'm looking for a solution within the script that runs at startup instead of separate solution such as adding a 2nd script to group policy that runs on shutdown
I've looked at WM_QUERYENDSESSION but I can't get it to work for powershell script.
Add the script on GPE on your local computer, So the script will run while shutdown.

What is the easiest way to run windows cron job

I'm currently using windows 7 with apache, php, and mysql. I understand on windows, task scheduler is the equivalence of cron jobs on linux/unix systems. I'm wondering what the easiest way to run a php file on my localhost server is through a task scheduler. I want it to open chrome (i know how to do that) but how do I set it to go to a certain page and close once it's finished the script.
A couple things come to mind...
One would be to utilize AutoIt which is a very powerful and public domain automation tool. You could easily start Chrome, navigate, verify on-screen values (e.g. when your script finishes), and then close chrome.
Another alternative would be to play bit more gorilla warfare tactic and terminate the process Chrome is using after some preset amount of time has elapsed (assuming you know how long this takes to run). See Windows' "TaskKill" command line options here: enter link description here

Windows Task Scheduler will run app only once

So my situation is that I am running an app on the Windows Task Scheduler. This app is run once a day at 1pm. the app does some queries and transfers data to an FTP site. All that is working great except on the weekends when i am not here the app is run and the GUI is still displayed for me to review. This seems to make it stop running on the scheduler until I shut down the app. So on Saturday it will run and the app will remain displayed for me to review when I get back on Monday. but on Sunday when the scheduler attempts to run it again it will fail because the app has not been closed down.
First let me confirm that this is how the Task Scheduler is supposed to work. Second, what are my alternatives for scheduling to run every day and keep the GUI displayed so that I can review. The app can run multiple times as each session does not interfere with the other sessions. So if I'm gone for a week on vacation I would expect that when i get back that 7 instances of the app have been run and are waiting for my review.
Thanks
AGP
Your best bet is to eliminate the UI and log messages to the Event Log or a log file. The UI could be spawned from the CLI as a separate process if you prefer, but it should be done so in as its own non-child process.
Alternatively, you could run a batch file instead of the process directly. In the batch file, invoke "START path_to_exe" instead of the EXE. That will cause the batch file to "finish" instantly, and the exe to be run in its own process. This is not a good long term solution, but will give you a temporary solution to your immediate problem.
This is the default behavior of the Scheduled Task system, as it doesn't know that the job is complete until the application actually exits. Therefore, if your application is still open after 24 hours, the next run will simply be skipped because the current run is "still going" as far as the scheduler is concerned.
Personally I would re-visit the way that you handle your job process, as your are setting up a scenario that will be hard to manage long term.
I recommend writing to a log file instead of displaying a UI for any output and/or errors. This way, the application can write, then exit, and you can review the log at your convenience. This is a very common solution for automated processes.

How do you schedule a daily script run on Windows XP?

I wrote a script in Ruby. I'd like to run it every day at a certain time. How do you do that on a Windows XP system?
I poked around on the machine and discovered the "scheduled tasks" control panel, but it doesn't seem to have anything to do with running scripts, as far as I can tell from the options offered by the "wizard".
Scheduled Tasks. Sometimes, you have to make a batch file call the script, and schedule the batch.
say you have "script.vbs" you want to run, you will have to create this batch:
cscript script.vbs
cscript is the windows script host which interprets the vbs script. I'm sure ruby has something similar.
You can do it with scheduled tasks, just browse for the program or script you want to run if it isn't listed (in this case, the ruby interpreter I guess, and add the name of the script to run as an argument).
Use the Windows task scheduler.
Under Control Panel > Schedule Tasks.
You can set it up to run any application or file executable from the command line.
Update: (1/15/09)
A good point from Wouter van Nifterick, remember to take care that the process finishes before the next one runs (in comments).
This can be done by going into the advanced options and adjust the allowed amount of time the task may run.
If the task is already configured open it and click the Settings tab. At the top of this tab you will see a checkbox followed by 'Stop the task if it runs for:' then there are two text boxes to enter hours and minutes. If your script runs once a day you will want this set to 23 hours or so.
The 'at' command is a nice command line version of a scheduler.

Resources