It seems that the issue is that the $billmsg variable is being overwritten in each iteration of the loop, resulting in all PPP secrets having the same comment. To fix this, you can modify the $billmsg variable by including the value of $item to create a unique value for each PPP secret:
@tomislav91
It’s time you try to understand what is being asked before answering…
@akira463
When you have two different comments like this
“Acc Number: 2021022 Plan: 35mbps Cost: 599”
“Acc Number: 2021021 Plan: 35mbps Cost: 4507”
You must search the original comment, for example “Acc Number: 2021022 Plan: 35mbps Cost: 599”, for replace it with new comment with updated cost,
not generically the profile that have the user “10 MBPS old 599 test”,
but you already have the item index $item inside the cycle, you not need to search again, just set the value on index,
and with putting the profile in the [find] you do not need to check it again inside if is present the comment or not.
I can not test the script because I do not have such profile and users, but must be like this:
/ppp secret
{
:local profCom “10 MBPS old 599 test”
:foreach item in=[find where profile=$profCom] do={
:local comm [get $item comment]
:local accNum [:pick $comm ([:find $comm "Number: “] + 8 ) [:find $comm " Plan:”]]
:local cost [:tonum [:pick $comm ([:find $comm "Cost: "] + 6) ([:len $comm])] ]
:local bill ($cost + 899)
:local billmsg “Acc Number: $accNum Plan: 10mbps Cost: $bill”
set $item comment=$billmsg
:delay 1s
}
}
Find the original comment by searching for a phrase like “Acc Number: 2021022” Plan: 35mbps Cost: 599", to update the profile with a new note reflecting the new price, rather than the generic “10 MBPS old 599 test”.