Hello sir, im having a trouble setting up the comment for all expired ppp users, here’s my code
/ppp secret
:foreach accName in=[find where profile="EXPIRED"] do={
:local date [/system clock get date]
:local name [get $accName name]
:local comm [/ppp secret get [find name=$accName] comment]
:local prof [/ppp secret get $accName profile]
:local accNum [:pick $comm ([:find $comm "Number: "] + 8) [:find $comm " Plan:"]]
:local plan [:pick $comm ([:find $comm "Plan: "] + 6) [:find $comm " Monthly"]]
:local monthlyBill [:pick $comm ([:find $comm "Bill: "] + 6) [:find $comm " Contact:"]]
:local contact [:pick $comm ([:find $comm "Contact: "] + 9) [:find $comm " Date"]]
:local dateInstalled [:pick $comm ([:find $comm "Installed: "] + 11) [:find $comm " Last"]]
:local lastPayment [:pick $comm ([:find $comm "Payment: "] + 9) [:find $comm " Expired"]]
:local balance [:pick $comm ([:find $comm "Bal: "] + 5) ([:len $comm])]
:local newComm "Acc Number: $accNum Plan: $plan Monthly Bill: $monthlyBill Contact: $contact Date Installed: $dateInstalled Last Payment: $lastPayment Expired Since: $date Bal: $total"
set $name comment=$newComm
}
please help me, thankyou!
A snipplet can not suffice, for example $total is missing and miss also what happen before and later
:local comm [/ppp secret get [find name=$accName] comment]
-> :local comm [get $accName comment]
:local prof [/ppp secret get $accName profile]
-> :local prof [get $accName profile]
set $name comment=$newComm
-> set $accName comment=$newComm
Never use field names as variable _name_s…
Also a nice formatted code help to understand and debug, is not only visual improvement:
/ppp secret
:foreach accName in=[find where profile=“EXPIRED”] do={
commented lines are unused
:local aName [get $accName name ]
:local prof [get $accName profile]
:local date [/system clock get date]
:local comm [get $accName comment]
:local accNum [:pick $comm ([:find $comm "Number: " ] + 8) [:find $comm " Plan:" ]]
:local plan [:pick $comm ([:find $comm "Plan: " ] + 6) [:find $comm " Monthly"]]
:local monthlyBill [:pick $comm ([:find $comm "Bill: " ] + 6) [:find $comm " Contact"]]
:local contact [:pick $comm ([:find $comm "Contact: " ] + 9) [:find $comm " Date" ]]
:local dateInstalled [:pick $comm ([:find $comm "Installed: "] + 11) [:find $comm " Last" ]]
:local lastPayment [:pick $comm ([:find $comm "Payment: " ] + 9) [:find $comm " Expired"]]
:local expiredSince [:pick $comm ([:find $comm “Since: " ] + 7) [:find $comm " Bal” ]]
:local balance [:pick $comm ([:find $comm "Bal: " ] + 5) [:len $comm ]]
:local newComm "Acc Number: $accNum \
Plan: $plan \
Monthly Bill: $monthlyBill \
Contact: $contact \
Date Installed: $dateInstalled \
Last Payment: $lastPayment \
Expired Since: $date \
Bal: $balance"
set $accName comment=$newComm
}
This code is corrected only against compiler errors, except $total that probably is defined before or is on reality $balance ???
Thankyou sir rextended , so much amazing! it works, i hope you never get tired of teaching us! long live !!!
Sir rextended i change some of the code, but the problem i does not work? ive been so dumb, cant figure out what could be wrong
my goal here is when expired since = “blank” then add current date, else rewrite the date since it was expired
/ppp secret
:foreach accName in=[find where profile="EXPIRED"] do={
# commented lines are unused
# :local aName [get $accName name ]
# :local prof [get $accName profile]
:local date [/system clock get date]
:local comm [get $accName comment]
:local accNum [:pick $comm ([:find $comm "Number: " ] + 8) [:find $comm " Plan:" ]]
:local plan [:pick $comm ([:find $comm "Plan: " ] + 6) [:find $comm " Monthly"]]
:local monthlyBill [:pick $comm ([:find $comm "Bill: " ] + 6) [:find $comm " Contact"]]
:local contact [:pick $comm ([:find $comm "Contact: " ] + 9) [:find $comm " Date" ]]
:local dateInstalled [:pick $comm ([:find $comm "Installed: "] + 11) [:find $comm " Last" ]]
:local lastPayment [:pick $comm ([:find $comm "Payment: " ] + 9) [:find $comm " Expired"]]
:local expiredSince [:pick $comm ([:find $comm "Since: " ] + 7) [:find $comm " Bal:" ]]
:local balance [:pick $comm ([:find $comm "Bal: " ] + 5) [:len $comm ]]
:if ($expiredSince = "") do={
:local newComm "Acc Number: $accNum \
Plan: $plan \
Monthly Bill: $monthlyBill \
Contact: $contact \
Date Installed: $dateInstalled \
Last Payment: $lastPayment \
Expired Since: $date \
Bal: $balance"
set $accName comment=$newComm
} else={
:local newComm "Acc Number: $accNum \
Plan: $plan \
Monthly Bill: $monthlyBill \
Contact: $contact \
Date Installed: $dateInstalled \
Last Payment: $lastPayment \
Expired Since: $expiredSince \
Bal: $balance"
set $accName comment=$newComm
}
}
Is not needed to duplicate all the string creation and
set $accName comment=$newComm
just write it one time at the end of if /else
If :pick not find any to pick, return nil, instead of one empty string,
nil can not be copared with empty string “”, not work.
You add : after Bal because some field can be confused? i suppose
/ppp secret
:foreach accName in=[find where profile=“EXPIRED”] do={
commented lines are unused
:local aName [get $accName name ]
:local prof [get $accName profile]
:local comm [get $accName comment]
:local accNum [:pick $comm ([:find $comm "Number: " ] + 8) [:find $comm " Plan:" ]]
:local plan [:pick $comm ([:find $comm "Plan: " ] + 6) [:find $comm " Monthly"]]
:local monthlyBill [:pick $comm ([:find $comm "Bill: " ] + 6) [:find $comm " Contact"]]
:local contact [:pick $comm ([:find $comm "Contact: " ] + 9) [:find $comm " Date" ]]
:local dateInstalled [:pick $comm ([:find $comm "Installed: "] + 11) [:find $comm " Last" ]]
:local lastPayment [:pick $comm ([:find $comm "Payment: " ] + 9) [:find $comm " Expired"]]
:local expiredSince [:pick $comm ([:find $comm "Since: " ] + 7) [:find $comm " Bal:" ]]
:local balance [:pick $comm ([:find $comm "Bal: " ] + 5) [:len $comm ]]
:if ([:typeof $expiredSince] != "str") do={
:set expiredSince [/system clock get date]
}
:local newComm "Acc Number: $accNum \
Plan: $plan \
Monthly Bill: $monthlyBill \
Contact: $contact \
Date Installed: $dateInstalled \
Last Payment: $lastPayment \
Expired Since: $expiredSince \
Bal: $balance"
set $accName comment=$newComm
}
Thankyou again Sir! now it works !!!
Hello
I need help to integrate my payment solution to mikrotic to generate automaticaly the tickets.
Ask ChatGPT for help, since you like it so much.
I don’t even consider that shit.
https://forum.mikrotik.com/viewtopic.php?p=1007642#p1007642
http://forum.mikrotik.com/t/ppp-schedule-change-profile-not-working/167415/1
And I don’t even reply to those who spam the forum.