Iceburg Posted May 10, 2010 Posted May 10, 2010 (edited) I have a script that runs 24/7 that is a scheduler script. Basically kicks off some other autoit scripts that are report scripts and e-mails data out daily / hourly, etc. Occasionally I will go in and do whatever I need to do one the machine and pause the script so there aren't Outlook Windows pop-ing up to send e-mail while I am working on that server. My problem is that occasionally I forget to un-pause the script and then reports don't run, and blah blah, I have to rush to fix it. Is there a way to "temporary" pause a script or have the script do something like if paused for 5 mins then unpause? Here is a sample of the code which is working perfect, except for my human intervention. =) while 1 $time = @HOUR & @MIN ;ConsoleWrite(@HOUR & @MIN & @SEC & @CRLF) ConsoleWrite($time & @CRLF) If $time == ("0645") Then Run ("C:\script1.exe") sleep(90000) ; prevent from running it a thousand times ElseIf $time == ("0700") Then Run ("C:\script2.exe") sleep(90000) ; prevent from running it a thousand times Elseif . . . . EndIf WEnd Edit: Typo Edited May 10, 2010 by Iceburg
ShawnW Posted May 10, 2010 Posted May 10, 2010 There is a way yes but I must ask why not use scheduled tasks built into windows?
somdcomputerguy Posted May 10, 2010 Posted May 10, 2010 (edited) The example code here, HotKeySet, pauses.Put your code in the while loop thats commented 'body of script' or something like that. In the while loop for the pause part, add two lines (to the end of the loop, before the WEnd); 1. Sleep(for however long you want), 2. Send(whatever hotkey you use to 'pause'). The example is a toggle, so Sending that Hotkey again will unpause your script. Edited May 10, 2010 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
ShawnW Posted May 10, 2010 Posted May 10, 2010 Anyway If you do wish you write your own pause function that times out and runs again after 5 minutes but will also unpause at will if you DO remember to press it again do something like this. Global $PauseTimer = 0 HotKeySet("{F1}","Pause") Func Pause() If $PauseTimer = 0 Then $PauseTimer += 600 ; 300 half seconds While $PauseTimer > 0 ToolTip($PauseTimer) Sleep(500) $PauseTimer -= 1 WEnd ToolTip("") Else $PauseTimer = 0 EndIf Return EndFunc While 1 WEnd When F1 is pressed, it should (untested might need adjustment) keep looping in a pause function every .5 seconds for 5 minutes. If it is pressed again however it sets the global timer to 0 which will cause the other instance of the function to end as well.
Iceburg Posted May 10, 2010 Author Posted May 10, 2010 @Shawn: Cause I want more flexibility, which is why everyone writes scripts, cause there is a need that isn't solved somewhere else. I have certain things that run on only the 1st of the month, some only on the 1st if its a weekday, etc. @somecomputerguy and Shawn(post 2): Thanks, that's what I needed, and I can tweak from there.
ShawnW Posted May 11, 2010 Posted May 11, 2010 well you can set all of those options and more with task scheduler. You can even use group policy or write your own script to add things to the scheduler. I am only nagging on this because I think you are overlooking what a powerful utility it is. I promise whatever scripts your running, I could find an easier way to run them on ANY schedule with task scheduler. It's whatever you want though just trying to inform you so that it might make your life easier on some project in the future.
Iceburg Posted May 11, 2010 Author Posted May 11, 2010 I have this running, but it only runs when the script is running within SciTE, when the script is compiled it doesn't work any more. Am I missing something?
Iceburg Posted May 11, 2010 Author Posted May 11, 2010 I can write a script to add something to the schedule? What do you mean? How is that easier than writing a script to do the scheduling, like I have now? =) Its a script either way.... I am not opposed to using Windows scheduler, I know its powerful, but I guess with the logging and such that I have written in, its easier to see what ran, what didn't and why all in one log file that's e-mailed to me at the end of the day.
ShawnW Posted May 11, 2010 Posted May 11, 2010 Adding a scheduled task with a script would just be an option if you want to have a type of script that adds a bunch of tasks to a machine, anyway just said you could not that you want to. As for the easier part I was saying that having a scheduled task call your scripts is easier. You still have all the logging and needed stuff that your current script does without having to worry about when it does it. The scheduled task would call your script at certain times. That is the easier part, no timing, no looping, no extra process always running in the background eating resources. It takes nothing away because everything your script does can still be done within the called script.
Iceburg Posted May 11, 2010 Author Posted May 11, 2010 Thanks Shawn, I understand where you're coming from. I am also new to AutoIt so any change to write scripts I just at the opportunity to write and learn something new. =) Anyway, any idea on when the script is compiled how to get the pause function or the HotKey to work, instead of when its just running in SciTE? -Nick
somdcomputerguy Posted May 11, 2010 Posted May 11, 2010 See the example code here, HotKeySet, which is a toggle-type pause function. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
ShawnW Posted May 11, 2010 Posted May 11, 2010 HotKeySet should work compiled just as well as run from scite. Make sure your not running 2 scripts with the same hotkey bindings.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now