Community discussions

MikroTik App
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Help with this script

Sat May 07, 2022 8:31 pm

Hello friends,
I have the following scripts that work very well separately, but I would like to make only one and thus be able to keep a record in the file.txt, I don't know if they understand what I want to do.
Thank you in advance for your help.
:global stopRouterRun false

:do {
             :local file "electric-cut.txt"
             :local data     [/system clock get date]
             :global arrMonths
             :local day      [:pick $data 4 6]
             :local mon     ($arrMonths->[:pick $data 0 3])
             :local year     [:pick $data 7 11]
             :local date "$day-$mon-$year"
             :local itime     [/system clock get time]
             :local hours   [:pick $itime 0 2]
             :local minsec [:pick $itime 2 8]
             :local mhours [:tonum $hours]
             :local msymbl "AM"
             :if ($mhours > 11) do={:set msymbl "PM"}
             :set mhours ($mhours % 12)
             :if ($mhours = 0) do={:set mhours 12}
             :if ($mhours < 10) do={:set mhours "0$mhours"}
             :local mtime "$mhours$minsec $msymbl"
             :local data1 "****************************\r\n      court:$date\r\n     at: $mtime\r\n****************************"
             /file
             :if ([:len [find where name=$file]] = 0) do={print file=$file; :delay 2; set $file contents=""}
             set $file contents=$data1

             :delay 60
} while=(!$stopRouterRun)

:delay 60
{
:local file "firtsstartup.txt"
:local intGoff [:tonum [/system clock get gmt-offset]]
:if ($intGoff > 86400) do={:set intGoff ((4294967296 - $intGoff) * -1)}
:local epochNow (([/tool fetch url="https://helloacm.com/api/unix-timestamp-converter/\3Fs=now" as-value output=user])->"data")
:local upTime [/system resource get uptime]
:local wPos   [:find $upTime "w" -1]
:local dPos   [:find $upTime "d" -1]
:local utLen  [:len $upTime]
:local utSec  [:pick $upTime ($utLen - 2) $utLen]
:local utMin  [:pick $upTime ($utLen - 5) ($utLen - 3)]
:local utHou  [:pick $upTime ($utLen - 8) ($utLen - 6)]
:local utDay  0
:local utWee  0
:if (([:typeof $wPos] = "nil") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime 0 $dPos] }
:if (([:typeof $wPos] = "num") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime ($wPos + 1) $dPos] }
:if ([:typeof $wPos] = "num") do={:set utWee [:pick $upTime 0 $wPos] }
:local totUtSec ($utSec + (60 * $utMin) + (60 * 60 * $utHou) + (60 * 60 * 24 * $utDay) + (60 * 60 * 24 * 7 * $utWee))
:local epochStart ($epochNow - $totUtSec + $intGoff)
:local datetimeStart (([/tool fetch url="https://helloacm.com/api/unix-timestamp-converter/\3Fs=$epochStart" as-value output=user])->"data")
:set datetimeStart [:pick $datetimeStart 1 ([:len $datetimeStart] - 1)]
:local year   [:pick $datetimeStart 0 4]
:local month  [:pick $datetimeStart 5 7]
:local day    [:pick $datetimeStart 8 10]
:local hms    [:pick $datetimeStart 11 19]
:local mhours [:tonum [:pick $hms 0 2]]
:local minsec [:pick $hms 2 8]
:local msymbl "AM"
:if ($mhours > 11) do={:set msymbl "PM"}
:set mhours ($mhours % 12)
:if ($mhours = 0) do={:set mhours 12}
:if ($mhours < 10) do={:set mhours "0$mhours"}
:local date "$day/$month/$year"
:local time "$mhours$minsec $msymbl"
:local started "****************************\r\n date: $date\r\n     time: $time\r\n****************************"
/file
:if ([:len [find where name=$file]] = 0) do={print file=$file; :delay 5; set $file contents=""}
set $file contents=$started
}

EL DONCITO.
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Help with this script

Sat May 07, 2022 10:41 pm

****************************           *****************************
      DATE: 07/05/2022                        COURT: 07/05/2022 
     TIME: 01:50:48 PM                         AT: 08:05:30 AM
****************************           ****************************
I would like to make a record of the courts and the reestablishment of the electrical service as seen in the previous





EL DONCITO
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help with this script

Sat May 07, 2022 10:57 pm

you really have a craze with this power on date and time...
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Help with this script

Sat May 07, 2022 11:12 pm

Ja ja ja ja, no friend REX, it's just to have a record in a file of when the electricity is cut off and when the service is restored, please help me friend REX.











EL DONCITO.
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Help with this script

Mon May 09, 2022 2:03 pm

Help me friend REX, please








EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help with this script

Mon May 09, 2022 2:29 pm

Not again with the same thing, I'm exhausted about that "when the device si booted", you have always dozen of scripts for that...
Is time than you try and study for yourself...
Helping has to be a pleasure, making so many corrections for the exact same thing, it feels like a job...

The forum is full of users, I hope someone help you again, or better, try and study
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Help with this script

Mon May 09, 2022 4:42 pm

You are right, what language does ROUTEROS use, or tell me where I can get material to document myself in script programming for mikrotik friend.





EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help with this script

Mon May 09, 2022 4:46 pm

You can use my various scripts as examples, and the first 3 search results on google for "mikrotik scripting":
https://wiki.mikrotik.com/wiki/Manual:Scripting
https://wiki.mikrotik.com/wiki/Manual:S ... g-examples
https://wiki.mikrotik.com/wiki/Manual:S ... and_Tricks

Who is online

Users browsing this forum: ohilton576 and 24 guests