number of pppoe active connections

On my routeros sometimes all pppoe active connections disappear (none active connection). I don’t know the cause of this problem but i solve it rebooting the router.
So i need a script that, if the number of active connections becomes zero, reboots automatically the router.
Can you help me ?

You should focus on solving the issue, rather then going for workarounds
any how you may try this, schedule it

{
    :local pppcount [/ppp active print count-only];
    :if ($pppcount < 1) do={
:log error "No User Found, Rebooting Router after 10 seconds of delay..."
delay 10
/sys reboot
    }
}