Community discussions

MikroTik App
 
andret
newbie
Topic Author
Posts: 37
Joined: Fri Apr 17, 2009 11:08 am

Determine day of week and hour of day in a script?

Thu May 14, 2009 7:04 pm

Hi

Is it possible to determine the hour of day and day of week within a script and execute a command in the event of a specific criteria?

Thanks
 
User avatar
omega-00
Forum Guru
Forum Guru
Posts: 1167
Joined: Sat Jun 06, 2009 4:54 am
Location: Australia
Contact:

Re: Determine day of week and hour of day in a script?

Fri May 15, 2009 10:44 am

Yeah pretty easy to do once you know how.

here's an excerpt from one of my scripts that checks if its the first day of any month.
:set date [/system clock get date]
:set time [/system clock get time]
:set month [:pick $date 0 3]
:set day [:pick $date 4 6]
:set year [:pick $date 7 11]
:set hour [:pick $time 0 2]
:set minute [:pick $time 3 5]
#Show variables for testing
:log info "The time is $hour:$minute and the date is $day / $month / $year" 
That'll give you all the details you could need each stored in their in their own variable and print it out in the log (so you can see what is generated)

You can then use something like this
:if ([$month] = "jan") do={   }
:if ([$month] = "feb") do={   }
:if ([$month] = "mar") do={   } 
:if ([$month] = "apr") do={   }
:if ([$month] = "may") do={   }
:if ([$month] = "jun") do={   }
:if ([$month] = "jul") do={   }
:if ([$month] = "aug") do={   }
:if ([$month] = "sep") do={   }
:if ([$month] = "oct") do={   }
:if ([$month] = "nov") do={   }
:if ([$month] = "dec") do={   }
To do something based on what month it is.. or modify to suit your needs.
 
andret
newbie
Topic Author
Posts: 37
Joined: Fri Apr 17, 2009 11:08 am

Re: Determine day of week and hour of day in a script?

Sun May 17, 2009 11:54 am

Excellent - Thanks!