Community discussions

MikroTik App
 
milad221
just joined
Topic Author
Posts: 8
Joined: Thu Jan 13, 2022 8:05 am

Script for Runnig interface

Sat Feb 25, 2023 9:50 am

Hi
I need a script in such a way that when the interface is out of run mode, it will be in run mode again with enable, and this script will be checked every minute.
mikrotik ver : 7.7
 
milad221
just joined
Topic Author
Posts: 8
Joined: Thu Jan 13, 2022 8:05 am

Re: Script for Runnig interface

Sat Feb 25, 2023 9:52 am

Sample code generated by ChatGBT:
/system script add name=check_l2tp source={
:local interface_name;
:foreach interface in=[/interface find type=l2tp-ethernet] do={
:set interface_name [/interface get $interface name];
:if ([/interface get $interface running]) do={
:put ("L2TP Ethernet interface '$interface_name' is already running.");
} else {
:put ("Starting L2TP Ethernet interface '$interface_name'...");
/interface enable $interface;
}
}
}
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 2865
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: Script for Runnig interface

Sat Feb 25, 2023 10:54 am

Sample code generated by ChatGBT:...
Really? Can't believe it ...
 
milad221
just joined
Topic Author
Posts: 8
Joined: Thu Jan 13, 2022 8:05 am

Re: Script for Runnig interface

Sat Feb 25, 2023 11:10 am

yes but don't work
Last edited by BartoszP on Sat Feb 25, 2023 11:53 am, edited 1 time in total.
Reason: removed excessive quotting of preceding post; be wise, quote smart. lines of quote, 1 line of post.
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 2865
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: Script for Runnig interface

Sat Feb 25, 2023 11:55 am

So what are you posting this nonworking code for? Just to promote chat?
 
User avatar
nichky
Forum Guru
Forum Guru
Posts: 1275
Joined: Tue Jun 23, 2015 2:35 pm

Re: Script for Runnig interface

Sat Feb 25, 2023 11:55 am

try this:

:global ifstatus
:if ([/interface ethernet get ether1 running]=true) do={
	:put "running"
	:if ($ifstatus="down") do={
		:put "changed to up"
	}
	:set $ifstatus "up"
} else={
	:put "not running"
	:if ($ifstatus="up") do={
		:put "changed to down"
	}
	:set $ifstatus "down"
}
 
milad221
just joined
Topic Author
Posts: 8
Joined: Thu Jan 13, 2022 8:05 am

Re: Script for Runnig interface

Sun Feb 26, 2023 10:43 am

try this:

:global ifstatus
:if ([/interface ethernet get ether1 running]=true) do={
	:put "running"
	:if ($ifstatus="down") do={
		:put "changed to up"
	}
	:set $ifstatus "up"
} else={
	:put "not running"
	:if ($ifstatus="up") do={
		:put "changed to down"
	}
	:set $ifstatus "down"
}
i running l2tp ethernet
change ethernet to l2tp ethernet ?
 
milad221
just joined
Topic Author
Posts: 8
Joined: Thu Jan 13, 2022 8:05 am

Re: Script for Runnig interface

Sun Feb 26, 2023 11:31 am

This script worked with a few changes, but if ether is not running, will it automatically run again?
 
milad221
just joined
Topic Author
Posts: 8
Joined: Thu Jan 13, 2022 8:05 am

Re: Script for Runnig interface

Sun Feb 26, 2023 11:54 am

try this:

:global ifstatus
:if ([/interface ethernet get ether1 running]=true) do={
	:put "running"
	:if ($ifstatus="down") do={
		:put "changed to up"
	}
	:set $ifstatus "up"
} else={
	:put "not running"
	:if ($ifstatus="up") do={
		:put "changed to down"
	}
	:set $ifstatus "down"
}
i running l2tp ethernet
change ethernet to l2tp ethernet ?
This script was tested. When Ether exits the run mode, it does not run again, even though the script counts.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script for Runnig interface

Sun Feb 26, 2023 5:23 pm

stop spam quotes everywhere.
It's ridiculous, simply modify last post if you want add something to yourself.
clean up the mess you made in previous posts: delete everything quoted.

Who is online

Users browsing this forum: alexantao and 19 guests