Sign in to follow this  
Followers 0
Burgs

5 minute scheduler?

8 posts in this topic

Greetings,

I'm trying to write a simple scheduler to run a program every "5 + 1" minutes, for example on minutes during the hour of "01, 06, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56". I know it requires a loop however I do not know the proper command syntax to set the minutes correctly. Any help appreciated.

Share this post


Link to post
Share on other sites



While 1
    If (StringRight(@MIN, 1) = 1) Or (StringRight(@MIN, 1) = 6) Then ;if current minute ends in 1 or 6
        ;run your program here
    EndIf
    Sleep(60000) ;pause for 60 seconds - you may want to change this, but if the program execution does not take at least a minute then it will run twice
WEnd


Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

While 1
    If (StringRight(@MIN, 1) = 1) Or (StringRight(@MIN, 1) = 6) Then ;if current minute ends in 1 or 6
        ;run your program here
    EndIf
    Sleep(60000) ;pause for 60 seconds - you may want to change this, but if the program execution does not take at least a minute then it will run twice
WEnd
Interesting. And a lot more elegant than I would have thought about doing it.

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]

Share this post


Link to post
Share on other sites

Interesting. And a lot more elegant than I would have thought about doing it.

You could simplify it even more using StringRegExp().

While 1
    If StringRegExp(@MIN, "[16]") = 1 Then ;if current minute ends in 1 or 6
        ;run your program here
    EndIf
    Sleep(60000) ;pause for 60 seconds - you may want to change this, but if the program execution does not take at least a minute then it will run twice
WEnd

The beauty of programming is the endless number of ways to obtain the same output.


Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Something like this should also work= (untested)

While 1
    If StringIsDigit((@MIN-1)/5) = 1 Then;if current minute ends in 1 or 6
      ;run your program here
    EndIf
    Sleep(60000);pause for 60 seconds - you may want to change this, but if the program execution does not take at least a minute then it will run twice
WEnd
Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites

Thanks for the help everybody! One final question, the application will run less than a minute, I thought of adding a "control" variable to prevent the script from running more than once but I'm getting an error, can somebody explain the problem with this? (it doesn't like the "Return" part...)

Dim $Control = 0

if($Control == 1) Then Return

EndIf

While 1

If (StringRight(@MIN, 1) = 1) Or (StringRight(@MIN, 1) = 6) Then ;if current minute ends in 1 or 6

;run your program here

Run("C:\SegFiles\Process.exe", "", @SW_MAXIMIZE)

$Control = 1

EndIf

Sleep(60000) ;pause for 60 seconds - you may want to change this, but if the program execution does not take at least a minute then it will run twice

WEnd

Share this post


Link to post
Share on other sites

1. return is used from inside a UDF

2. it is written either...

If ($Control == 1) Then Return ; with no "EndIf"

or.....

If ($Control == 1) Then

; do something

Return

EndIf

how about this, it only sleeps for 1 min when the prog is ran?

While 1
    If (StringRight(@MIN, 1) = 1) Or (StringRight(@MIN, 1) = 6) Then ;if current minute ends in 1 or 6
        ;run your program here
        Run("C:\SegFiles\Process.exe", "", @SW_MAXIMIZE)
        Sleep(60000)
    EndIf
    Sleep(10)
WEnd

Very Important, Scite can test the syntax for errors ... just click "sytaxcheckprod" under "tools"

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thank you for the reply, that's a great help to me!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0