Community discussions

MikroTik App
 
amin1356
just joined
Topic Author
Posts: 9
Joined: Wed May 06, 2015 5:52 pm

Script for OVPN users

Wed Mar 01, 2023 4:06 pm

Hi,
I need Script on my MikroTik server for checking connected OVPN users and remove any OVPN users that its uptime more than 1 Minute but Tx is 0.
Something like this:
int ovpn-server remove [find uptime>00:01:00 Tx=0]
but above script doesn't work!
anyone can help?
Thanks,
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script for OVPN users

Wed Mar 01, 2023 7:59 pm

Tx not exist.
Last edited by rextended on Wed Mar 01, 2023 8:12 pm, edited 2 times in total.
 
amin1356
just joined
Topic Author
Posts: 9
Joined: Wed May 06, 2015 5:52 pm

Re: Script for OVPN users

Wed Mar 01, 2023 8:09 pm

Tx not exist.
What about "Tx Bytes" ?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script for OVPN users

Wed Mar 01, 2023 8:12 pm

I do not use OVPN.
On terminal paste this, using one OVPN real interface name
:put [/interface get <ovpn-test>]
Search on results how the wanted field are called, for example "...;tx-byte=541654;...".

Replace tx-byte on following script with the corect name:

probably working code

/interface ovpn-server remove [find where ((uptime > 00:01:00) and ([/interface get $name tx-byte] = 0))]
If you use this on scripts, DO NOT DECLARE any variable called "name" on the script...

I can not test it, so no warranty that works,
but is nice if you write is work or not for other users.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script for OVPN users

Wed Mar 01, 2023 8:46 pm

Tx not exist.
What about "Tx Bytes" ?
You test the script?
 
amin1356
just joined
Topic Author
Posts: 9
Joined: Wed May 06, 2015 5:52 pm

Re: Script for OVPN users

Wed Mar 01, 2023 10:27 pm

I do not use OVPN.
On terminal paste this, using one OVPN real interface name
:put [/interface get <ovpn-test>]
Search on results how the wanted field are called, for example "...;tx-byte=541654;...".

Replace tx-byte on following script with the corect name:

probably working code

/interface ovpn-server remove [find where ((uptime > 00:01:00) and ([/interface get $name tx-byte] = 0))]
If you use this on scripts, DO NOT DECLARE any variable called "name" on the script...

I can not test it, so no warranty that works,
but is nice if you write is work or not for other users.
[admin@MikroTik] > :put [/interface get <ovpn-amin1356>]
.id=*f00e1b;actual-mtu=1400;disabled=false;dynamic=true;fp-rx-byte=0;
fp-rx-packet=0;fp-tx-byte=0;fp-tx-packet=0;last-link-up-time=mar/01/2
023 23:19:14;link-downs=0;mtu=1500;name=<ovpn-amin1356>;running=true;
rx-byte=594633;rx-drop=0;rx-error=0;rx-packet=3255;tx-byte=11926821;t
x-drop=0;tx-error=0;tx-packet=10736;tx-queue-drop=0;type=ovpn-in

it seems there is no "uptime" (online duration) field!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script for OVPN users

Wed Mar 01, 2023 11:28 pm

it seems there is no "uptime" (online duration) field!
It doesn't matter, matter only the existance of "tx-byte".
You don't have to change that parameter there, try the script (if any is blocked, obviously do not return anything if all is ok...)
 
amin1356
just joined
Topic Author
Posts: 9
Joined: Wed May 06, 2015 5:52 pm

Re: Script for OVPN users

Wed Mar 01, 2023 11:46 pm

it seems there is no "uptime" (online duration) field!
It doesn't matter, matter only the existance of "tx-byte".
You don't have to change that parameter there, try the script (if any is blocked, obviously do not return anything if all is ok...)
/interface ovpn-server remove [find where ((uptime > 00:01:00) and ([/interface get $name tx-byte] = 0))]

with above command nothing happened but the following command seems to remove any user with tx-byte=0 :

/interface ovpn-server remove [find where ([/interface get $name rx-byte] = 0)]

I need more test for the exact result ....
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script for OVPN users

Thu Mar 02, 2023 12:24 am

I can not test it because do not have OVPN ,as I already wrote,

but you put Rx- on script not Tx-...
 
amin1356
just joined
Topic Author
Posts: 9
Joined: Wed May 06, 2015 5:52 pm

Re: Script for OVPN users  [SOLVED]

Thu Mar 02, 2023 6:50 am

Thank you @rextended,
/interface ovpn-server remove [find where ([/interface get $name rx-byte] = 0)]

Solved my problem.

Who is online

Users browsing this forum: rogerioqueiroz and 21 guests