Community discussions

MikroTik App
 
runbound
Member Candidate
Member Candidate
Topic Author
Posts: 125
Joined: Fri Apr 19, 2013 9:28 am

all ppp profile  [SOLVED]

Thu Mar 24, 2022 9:35 am

pls help how to print all profile name with starts with the name FIBR
i have a script but it print only 1

:put ([/ppp profile print as-value where name~"FIBR"] ->1->"name")
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7038
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: all ppp profile

Thu Mar 24, 2022 11:03 am

You are picking one element from an array, instead you should run foreach loop to go through all the elements of an array.
 
runbound
Member Candidate
Member Candidate
Topic Author
Posts: 125
Joined: Fri Apr 19, 2013 9:28 am

Re: all ppp profile

Thu Mar 24, 2022 11:11 am

how can u give me an example pls
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: all ppp profile

Thu Mar 24, 2022 2:19 pm

You need to find what you are looking for, then get all the data for the ID that find returns.
print should not be used in script.
:foreach Profile in=[/ppp profile find where name~"FIBR"] do={:put [/ppp profile get $Profile]}
Some more clean setup.
/ppp profile
:foreach Profile in=[find where name~"FIBR"] do={
	:put [/ppp profile get $Profile]
}
If you like to try this at command line, you need to wrap it in {} (since its more than one line), so:
{
/ppp profile
:foreach Profile in=[find where name~"FIBR"] do={
	:put [/ppp profile get $Profile]
}
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: all ppp profile

Thu Mar 24, 2022 3:36 pm

get.. NAME... :-P

containing "FIBR" (CASE SENSITIVE!!!)
/ppp profile
:foreach profID in=[find where name~"FIBR"] do={
    :put [get $profID name]
}

starts with "FIBR" (CASE SENSITIVE!!!)
/ppp profile
:foreach profID in=[find where name~"^FIBR"] do={
    :put [get $profID name]
}

Notice:
[get $profID name]
or
([get $profID]->"name")
on this case are equivalents, but the first is more readable
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: all ppp profile

Thu Mar 24, 2022 5:33 pm

Hmm

I hoped that this should work, but it does not:
name~"(?i)fibr"
Did try this as well, but does not work.
name~"(\?i)fibr"
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: all ppp profile

Thu Mar 24, 2022 6:24 pm

MikroTik use syntax compatible only with POSIX RegEx, but without "Character Classes" and is not present support for other platform RegEx syntax

start with
name~"^[Ff][Ii][Bb][Rr]"
or
name~"^(F|f)(I|i)(B|b)(R|r)"

contain
name~"[Ff][Ii][Bb][Rr]"
or
name~"(F|f)(I|i)(B|b)(R|r)"
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: all ppp profile

Thu Mar 24, 2022 8:03 pm

MT does not handle upper/lower case very good.
Missing toupper/tolower (?i) +++
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: all ppp profile

Thu Mar 24, 2022 8:06 pm

missing also RegEx on :find... :(
 
runbound
Member Candidate
Member Candidate
Topic Author
Posts: 125
Joined: Fri Apr 19, 2013 9:28 am

Re: all ppp profile

Fri Mar 25, 2022 7:18 am

thanks for the help it works. but how can i send this through sms. not working

/ppp profile
:foreach profID in=[find where name~"FIBR"] do={
:log warning message=[get $profID name]
:local plan [get $profID name]
}

:log warning message="send to sms"
/tool sms send phone-number=056698885 message="$plan"


}
}
} on-error={:log error message="script failed..."}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: all ppp profile

Fri Mar 25, 2022 2:09 pm

The script you write can not work because :local variables inside "{" are lost at first "}" and if global is used, return only the last profile with "FIBR" inside

You first try on terminal to see if the machine send SMS?
/tool sms send phone-number=056698885 message="test"

Probably you need something like this:

One SMS for each profile containing FIBR
/ppp profile
:foreach profID in=[find where name~"FIBR"] do={
    :log warning message="send $[get $profID name] to SMS"
    /tool sms send phone-number=056698885 message=[/ppp profile get $profID name]
}

Only one unique SMS with all profiles that containing FIBR
(single SMS is max 160 characters!!!)
{
/ppp profile
:local allprofiles ""
:foreach profID in=[find where name~"FIBR"] do={
    :if ($allprofiles="") do={ :set allprofiles [get $profID name] } else={ :set allprofiles "$allprofiles,$[get $profID name]" }
}
:log warning message="send $allprofiles to SMS"
/tool sms send phone-number=056698885 message=$allprofiles
}
 
runbound
Member Candidate
Member Candidate
Topic Author
Posts: 125
Joined: Fri Apr 19, 2013 9:28 am

Re: all ppp profile

Fri Mar 25, 2022 3:28 pm

it works. thank u very much sir rextended
lastly how to pick it like for example i want to remove the name FIBR when i recieved the sms
like for example

instead of
FIBR 12 10MBPS
FIBR 15 15MBPS
FIBR 17 17MBPS

they reiceved the message of
12 10MBPS
15 15MBPS
17 17MBPS
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: all ppp profile

Fri Mar 25, 2022 4:00 pm

please be more clear, you want remove FIBR on COMMENTed profile, or INSIDE SMS?
 
runbound
Member Candidate
Member Candidate
Topic Author
Posts: 125
Joined: Fri Apr 19, 2013 9:28 am

Re: all ppp profile

Fri Mar 25, 2022 4:12 pm

on sms sir
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: all ppp profile

Fri Mar 25, 2022 4:20 pm

Removing "FIBR " (and space):

One SMS for each profile containing FIBR and removing "FIBR " on SMS
/ppp profile
:foreach profID in=[find where name~"FIBR"] do={
    :local profname [get $profID name]
    # 5 is the lenght of prefix FIBR including space
    :set profname [:pick $profname ([:find $profname "FIBR "] + 5) [:len $profname]]
    :log warning message="send $profname to SMS"
    /tool sms send phone-number=056698885 message=$profname
}

Only one unique SMS with all profiles that containing FIBR and removing "FIBR " on SMS
(single SMS is max 160 characters!!!)
{
/ppp profile
:local allprofiles ""
:foreach profID in=[find where name~"FIBR"] do={
    :local profname [get $profID name]
    # 5 is the lenght of prefix FIBR including space
    :set profname [:pick $profname ([:find $profname "FIBR "] + 5) [:len $profname]]
    :if ($allprofiles="") do={ :set allprofiles [get $profID name] } else={ :set allprofiles "$allprofiles,$profname" }
}
:log warning message="send $allprofiles to SMS"
/tool sms send phone-number=056698885 message=$allprofiles
}
 
runbound
Member Candidate
Member Candidate
Topic Author
Posts: 125
Joined: Fri Apr 19, 2013 9:28 am

Re: all ppp profile

Tue Jun 14, 2022 6:12 am

thanks sir ,
how about not to include my current profile in sms

example my current profile is 15 15MBPS

12 10MBPS
15 15MBPS (remove this)
17 17MBPS
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: all ppp profile

Tue Jun 14, 2022 10:18 am

explain better, and where I can see the current profile?
 
runbound
Member Candidate
Member Candidate
Topic Author
Posts: 125
Joined: Fri Apr 19, 2013 9:28 am

Re: all ppp profile

Tue Jun 14, 2022 3:07 pm

if my subscriber have a plan of 5MBPS in ppp secret profile
and text 9. i want reply of my system to my subscriber all profile~FIBR but not included the current plan of my subscriber



:foreach i in=[/tool sms inbox find where message="9"] do={
:local smsPhone [/tool sms inbox get $i phone];
:local old [ :pick $smsPhone 3 14 ]

:if ([/ppp secret find where profile~"FIBR" ipv6-routes="$old" && comment>"-4"]) do={
:local sname [/ppp secret get [find ipv6-routes="$old"] name];
:local profile [/ppp secret get [find ipv6-routes="$old"] profile];
:local prof1 [ :pick $profile 0 4 ];
:local prof2 [ :pick $profile 5 9 ];
:local prof3 [ :pick $profile 10 17 ];


:local allprofiles
/ppp profile
:foreach profID in=[find where name~"FIBR"] do={
:local profname [get $profID name]
:set profname [:pick $profname ([:find $profname] + 5) [:len $profname]]
:if ($allprofiles="") do={ :set allprofiles [get $profID name] } else={ :set allprofiles "$allprofiles\r\n$profname" }
}

/tool sms send phone="$old" message="UR CURRENT PLAN is:
$prof1 $prof2 $prof3

PLAN AVAILABLE:$allprofiles

-$identity"
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: all ppp profile

Tue Jun 14, 2022 3:41 pm

you can replace

foreach profID in=[find where name~"FIBR"] do={

with something like

foreach profID in=[find where name~"FIBR" and name!=$currentprofilename] do={
 
runbound
Member Candidate
Member Candidate
Topic Author
Posts: 125
Joined: Fri Apr 19, 2013 9:28 am

Re: all ppp profile

Wed Jun 15, 2022 3:50 am

thank you sir for your help
one more sir

how can i order it from lower to higher price
i received like this
20 20MBPS
10 `10MBPS
30 30MBPS
5 5MBPS
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: all ppp profile

Wed Jun 15, 2022 10:09 am

too complex with limited scripting capabilities...

Who is online

Users browsing this forum: infabo, JDF and 25 guests