Script to inform by email when the equipment was restarted due to power failure

Hello rextended

Sorry for the late reply, I was recovering from surgery.

I modified the second part of the script, not sure if it was the smartest way, or the prettiest one, but it works

:delay 60s

:global datetime2epoch do={
    :local vdate [:pick $1 0 [:find $1 " " -1]]
    :local vtime [:pick $1 ([:find $1 " " -1] + 1) [:len $1]]
    :local vgmt  [/system clock get gmt-offset]; :if ($vgmt > 0x7FFFFFFF) do={:set vgmt ($vgmt - 0x100000000)}
    :if ($vgmt < 0) do={:set vgmt ($vgmt * -1)}
    :local arrm  [:toarray "0,0,31,59,90,120,151,181,212,243,273,304,334"]
    :local yyyy  [:pick $vdate 7 11] ; :if ((($yyyy - 1972) % 4) = 0) do={:set ($arrm->1) -1; :set ($arrm->2) 30}
    :local M     ([:find "xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC" [:pick $vdate 1 3] -1] / 2); :if ($M>12) do={:set M ($M - 12)}
    :local totd  ((($yyyy - 1970) * 365) + (($yyyy - 1972) / 4) + ($arrm->$M) + [:pick $vdate 4  6])
    :return      (((((($totd * 24) + [:pick $vtime 0  2]) * 60) + [:pick $vtime 3  5]) * 60) + [:pick $vtime 6  8] - $vgmt)
}

{
/system clock
:local datetimestr "$[get date] $[get time]"
:local filename "clock.txt"
:if ([:len [/file find where name="flash" and type="disk"]]=1) do={:set filename "flash/$filename"}

:local lastdatetime [/file get [find where name=$filename] contents]

:local unixnow   [$datetime2epoch ("$[/sys clock get date] $[/sys clock get time]")]
:local timestamp [$datetime2epoch $lastdatetime]
:local diff      ($unixnow - $timestamp)

:local time $diff

:local days ($time / 60 / 60 / 24)
:local hours (($time / 60 / 60) % 24)
:local minutes (($time / 60) % 60)
:local seconds ($time % 60)

:local days ($days+00)
:local hours ($hours+00)
:local minutes ($minutes+00)
:local seconds ($seconds+00)

[:parse ":local timeoff ($hours:$minutes:$seconds)"]
:local timeoff ($days."d"." ".$timeoff)

/tool e-mail send \
   to=email@email.com \
   subject="$[/system identity get name] - Router was rebooted - Time off: $timeoff" \
   body=" $lastdatetime, $[/system identity get name] - Time the router was rebooted\n \
         $datetimestr, $[/system identity get name] - Router was rebooted after\n \
         $timeoff"
}