Page 1 of 1

Help me to complete the script

Posted: Sun Jul 03, 2016 3:30 pm
by cutedrummerboy
hi,
i am not good at scripting, can anyone help me to complete the script. basically i want to send a message at 3 or 4 numbers at once
:log info "Alert: Internet is Down at $[/system clock get time]";
:local SMSNumbers { "XXXXXXXXXX", \
                         "YYYYYYYYYY", \
                         "ZZZZZZZZZZ" };
:foreach r in=[:toarray $SMSNumbers] do={
    :put [:tostr $r]
    /tool sms send message="Alert: Internet is Down at $[/system clock get time]" phone-number=$SMSNumbers usb2;
    delay 2;
}

Re: Help me to complete the script

Posted: Sun Jul 03, 2016 4:51 pm
by darkprocess
You can't. One at a time

Re: Help me to complete the script

Posted: Sun Jul 03, 2016 5:02 pm
by cutedrummerboy
:shock: this is not fair.... is there any chance ??

Re: Help me to complete the script

Posted: Sun Jul 03, 2016 5:33 pm
by darkprocess
I'm mistaken it works in a loop. I'm not so good in scripting

Re: Help me to complete the script

Posted: Mon Jul 04, 2016 11:35 am
by cutedrummerboy
is there any script guru who can help me to complete this script?? i don't to know how to loop.

Re: Help me to complete the script

Posted: Mon Jul 04, 2016 11:27 pm
by pe1chl
The script already has a loop but you pass the wrong info to the SMS tool.
It should be phone-number=$r

Re: Help me to complete the script

Posted: Wed Jul 20, 2016 11:39 am
by Deantwo
The script already has a loop but you pass the wrong info to the SMS tool.
It should be phone-number=$r
You are correct.
But it also seems like the array isn't being defined correctly since the foreach treats it as one long string. Array elements have to be separated with semi-colons when being defined.

Here is the corrected script:
:local alertMessage "Alert: Internet is Down at $[/system clock get time]"
:log info $alertMessage
:local smsNumberList { "XXXXXXXXXX" \
                     ; "YYYYYYYYYY" \
                     ; "ZZZZZZZZZZ" \
                     }
:foreach smsNumber in=$smsNumberList do={
    :put ("SMSing " . $smsNumber)
    /tool sms send port="usb2" phone-number=$smsNumber message=$alertMessage
    delay 2
}
I did a few minor changes too.

I suggest reading the scripting manual page some more on the subject of arrays if you intend on using them.
Here: wiki.mikrotik.com/wiki/Manual:Scripting