Script not running OK - geting MAC from wireless registration?

Hello ,
I’m using RB912UAG with v 6.40.1
and I have a this simple script

  name="GetWirelessMac" owner="admin" 
     policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon 
     last-started=jun/13/2018 14:28:35 run-count=14733 
     source=
       :global MAC;
       :if ([/interface wireless registration-table print count-only ] != 0) do={:
set MAC [/interface wireless registration-table get number=0 mac-address]} 
else={:set MAC 0};
       
       :put $MAC;
       :log warning "$MAC";

that run once every 30 seconds

the thing is that very often I get in the log an empty line when a device is connected\not connected - I’m not gettting MAC or 0 …

but if I run the script in terminal - it’s working , what could it be ?

Thanks ,