Menu

Euodeio.NET

Get off my lawn.

Mikrotik time to seconds

Needed a function to get a ospf neighbor adjacency time in seconds, to check flaps...

Most code is copy-pasted from the script by Mark Frater in the mkt forums.

:global timeToSeconds do={
    :local iSeconds 0; :local upTxt $1; :local daypos 0;
    :for pos from=0 to=([:len $upTxt] - 8) do={
        :if ([:pick $upTxt $pos] = "w") do={
            :set iSeconds ( [:pick $upTxt 0 ($pos)] * 7 * 24 * 60 * 60 );
            :set daypos ($pos+1);
        }
        :if ([:pick $upTxt $pos] = "d") do={
            :set iSeconds ( $iSeconds + ([:pick $upTxt ($daypos) ($pos)] * 24 * 60 * 60) );
        }
    }
    :set iSeconds ( $iSeconds + ([:pick $upTxt ([:len $upTxt]-8) ([:len $upTxt]-6)] * 60 * 60) );
    :set iSeconds ( $iSeconds + ([:pick $upTxt ([:len $upTxt]-5) ([:len $upTxt]-3)] * 60) );
    :return $iSeconds;
}
:put [$timeToSeconds "1w3d10:51:24"]

Escrito por Eliphas em Friday January 27, 2017

Link permanente - Category: life - Tags: music, film, fiction, astronomy, writing

« Using the WPS button to unblock a connected MAC in openwrt