Community discussions

MikroTik App
 
angboontiong
Forum Guru
Forum Guru
Topic Author
Posts: 1136
Joined: Fri Jan 16, 2009 9:59 am

reboot router if pppoe server client count=0

Wed Jan 06, 2021 8:44 pm

Hi,
can share with me how to do the script to monitor the pppoe server, when print count = 0, then to reboot the routerboard?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: reboot router if pppoe server client count=0

Wed Jan 06, 2021 9:51 pm

So when router comes up, it will still have client count=0 and will be rebootet again? Bootloop.
You should try to fix/find the problem so you do not need reboot.
 
User avatar
tomaskir
Trainer
Trainer
Posts: 1162
Joined: Sat Sep 24, 2011 2:32 pm
Location: Slovakia

Re: reboot router if pppoe server client count=0

Wed Jan 06, 2021 10:59 pm

As said above, you should fix whatever are the underlying issues rather than reboot.

However, here is a script that will reboot the router, if uptime is over 1 minute, and there are 0 PPPoE sessions:
{
:local upTime [/system resource get uptime]
:local weeks [:pick $upTime 0 [:find $upTime "w"]]
:set upTime [:pick $upTime ([:find $upTime "w"]+1) [:len $upTime]]
:local days [:pick $upTime 0 [:find $upTime "d"]]
:set upTime [:pick $upTime ([:find $upTime "d"]+1) [:len $upTime]]
:local hours [:pick $upTime 0 [:find $upTime ":"]]
:set upTime [:pick $upTime ([:find $upTime ":"]+1) [:len $upTime]]
:local minutes [:pick $upTime 0 [:find $upTime ":"]]
:set upTime [:pick $upTime ([:find $upTime ":"]+1) [:len $upTime]]
:local seconds $upTime

:local upSeconds [(($weeks*604800)+($days*86400)+($hours*3600)+($minutes*60)+$seconds)]

:if ($upSeconds > 60) do={
  :if ([:len [/interface pppoe-server find]] = 0) do={
    /system reboot
  }
}
}
You can put this into the scheduler, and schedule it to run in a 1 minute interval if you want.

Uptime script stolen from here: viewtopic.php?t=88168#p443779
 
angboontiong
Forum Guru
Forum Guru
Topic Author
Posts: 1136
Joined: Fri Jan 16, 2009 9:59 am

Re: reboot router if pppoe server client count=0

Thu Jan 07, 2021 6:03 pm

As said above, you should fix whatever are the underlying issues rather than reboot.

However, here is a script that will reboot the router, if uptime is over 1 minute, and there are 0 PPPoE sessions:
{
:local upTime [/system resource get uptime]
:local weeks [:pick $upTime 0 [:find $upTime "w"]]
:set upTime [:pick $upTime ([:find $upTime "w"]+1) [:len $upTime]]
:local days [:pick $upTime 0 [:find $upTime "d"]]
:set upTime [:pick $upTime ([:find $upTime "d"]+1) [:len $upTime]]
:local hours [:pick $upTime 0 [:find $upTime ":"]]
:set upTime [:pick $upTime ([:find $upTime ":"]+1) [:len $upTime]]
:local minutes [:pick $upTime 0 [:find $upTime ":"]]
:set upTime [:pick $upTime ([:find $upTime ":"]+1) [:len $upTime]]
:local seconds $upTime

:local upSeconds [(($weeks*604800)+($days*86400)+($hours*3600)+($minutes*60)+$seconds)]

:if ($upSeconds > 60) do={
  :if ([:len [/interface pppoe-server find]] = 0) do={
    /system reboot
  }
}
}
You can put this into the scheduler, and schedule it to run in a 1 minute interval if you want.

Uptime script stolen from here: viewtopic.php?t=88168#p443779
thanks for you sharing.
after post i found some similar then i amended to fit what i want.

:local PppoeClient [/interface pppoe-server print count-only];
:local CompareClient 0

#:log info ($PppoeclientInfo);

:if ($PppoeClient <= $CompareClient) do={
#:log info ($PppoeclientInfo);
/system reboot
}

Who is online

Users browsing this forum: jaclaz and 23 guests