Community discussions

MikroTik App
 
User avatar
lio00lio
just joined
Topic Author
Posts: 21
Joined: Fri May 18, 2012 1:34 pm
Location: Italy

Script - IP Check USB MODEM

Mon Oct 21, 2019 6:31 pm

Hi all,
I'll try to make a script to check a WAN status, the case is:
USB Modem on RB.
In case of blocking of only the connectivity to a usb reset for some times, after X times to reboot of RB.
I'll try with this code, but not work:
{
:log warning "START-SCRITP CONTROLL"
:global CheckTimes;
:global CheckRunStatus;

:log error "logCheckTimes = $CheckTimes"
:log error "logCheckRunStatus = $CheckRunStatus"

:if ($CheckRunStatus = 1) do={
:log error "Allready running..."
:error break;
} else={
:set CheckRunStatus 1;
:if ($CheckTimes = 5) do={
:log error "Reboot now"
/system reboot;

} else={

:local HOST "8.8.8.8"
:local PINGCOUNT "30"
:local DELAY "10s"

:if ([/ping $HOST interval=1 count=$PINGCOUNT] = 0) do={
:log error "HOST $HOST is not responding to ping request, reseting USB interface ..."
/system routerboard usb power-reset duration=10s;
:log error "USB is now disabled, waiting $DELAY ..."
:delay $DELAY;
:local app $CheckTimes+1;
:set CheckTimes $app;

} else {
:log warning "HOST $HOST ping is ok, no need to take any action ...";
:set CheckRunStatus 0;
:set CheckTimes 0;
}
:set CheckRunStatus 0;

}
}
:log warning "END-SCRITP CONTROLL";
}
Does someone have an idea?
Last edited by lio00lio on Tue Oct 22, 2019 2:44 pm, edited 1 time in total.
 
User avatar
lio00lio
just joined
Topic Author
Posts: 21
Joined: Fri May 18, 2012 1:34 pm
Location: Italy

Re: Script - IP Check USB MODEM  [SOLVED]

Tue Oct 22, 2019 2:44 pm

Solve
I share the code of script:
:log warning "START SCRITP Netcontroller";
:global CheckTimes;
:global CheckRunStatus;
:global Times "2";

:if ($CheckRunStatus = 1) do={
	:log error "Allready running";
	:error break;
} else={
	:set CheckRunStatus 1;
	### Controllo se non ha avuto più di X ricorsività ###
	:if ($CheckTimes = $Times) do={
	:log error "Reboot now";
	/system reboot;
} else={
:local HOST "8.8.8.8";
:local PINGCOUNT "36";
:local PINGINTERVAL "5";
:local DELAY "10s";
	:if ([/ping $HOST interval=$PINGINTERVAL count=$PINGCOUNT] = 0) do={
		:log error "HOST $HOST is not responding to ping request, reseting USB interface";
		/system routerboard usb power-reset duration=10s;
		:log error "USB is now disabled, waiting $DELAY";
		:delay $DELAY;
		:set CheckTimes ($CheckTimes + 1);
	} else {
		:log warning "HOST $HOST ping is ok, no need to take any action ";
		:set CheckRunStatus 0;
		:set CheckTimes 0;
	}
:set CheckRunStatus 0;
}
}
:log warning "END SCRITP Netcontroller";

enjoy

Who is online

Users browsing this forum: No registered users and 14 guests