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;
}
this is not fair… is there any chance ??
I’m mistaken it works in a loop. I’m not so good in scripting
is there any script guru who can help me to complete this script?? i don’t to know how to loop.
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