VRRP on-backup-script not running

I’ve solved the startup issue this way:

I’ve scheduled the following to run on startup:

/system script run vrrpCheck

The script vrrpCheck basically runs the onBackup, then waits for a while before it checks if there is any vrrp master interfaces. If there is, it runs onMaster. The script looks like this:

:global mstr;
:set mstr 0
:delay 3
/system script run onBackup
:delay 8
foreach i in=[/interface vrrp find master=yes] do={
set mstr 1
}
:if ($mstr = 1) do={
/system script run onMaster
}

vrrp interface is defined to run the scripts onMaster and onBackup scripts on the events.
And I have the scrips onMaster and onBackup that performs what I want them to do.