Community discussions

MikroTik App
 
cutedrummerboy
Member Candidate
Member Candidate
Topic Author
Posts: 137
Joined: Thu Nov 14, 2013 6:32 pm

Help me to complete the script

Sun Jul 03, 2016 3:30 pm

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;
}
Device: RB2011UIAS-RM, RB750GL, CISCO SG300-28, UNIFI UAP-LR
 
darkprocess
Member Candidate
Member Candidate
Posts: 255
Joined: Fri Mar 20, 2015 1:16 pm

Re: Help me to complete the script

Sun Jul 03, 2016 4:51 pm

You can't. One at a time
 
cutedrummerboy
Member Candidate
Member Candidate
Topic Author
Posts: 137
Joined: Thu Nov 14, 2013 6:32 pm

Re: Help me to complete the script

Sun Jul 03, 2016 5:02 pm

:shock: this is not fair.... is there any chance ??
Device: RB2011UIAS-RM, RB750GL, CISCO SG300-28, UNIFI UAP-LR
 
darkprocess
Member Candidate
Member Candidate
Posts: 255
Joined: Fri Mar 20, 2015 1:16 pm

Re: Help me to complete the script

Sun Jul 03, 2016 5:33 pm

I'm mistaken it works in a loop. I'm not so good in scripting
 
cutedrummerboy
Member Candidate
Member Candidate
Topic Author
Posts: 137
Joined: Thu Nov 14, 2013 6:32 pm

Re: Help me to complete the script

Mon Jul 04, 2016 11:35 am

is there any script guru who can help me to complete this script?? i don't to know how to loop.
Device: RB2011UIAS-RM, RB750GL, CISCO SG300-28, UNIFI UAP-LR
 
pe1chl
Forum Guru
Forum Guru
Posts: 6660
Joined: Mon Jun 08, 2015 12:09 pm

Re: Help me to complete the script

Mon Jul 04, 2016 11:27 pm

The script already has a loop but you pass the wrong info to the SMS tool.
It should be phone-number=$r
 
User avatar
Deantwo
Member
Member
Posts: 314
Joined: Tue Sep 30, 2014 4:07 pm

Re: Help me to complete the script

Wed Jul 20, 2016 11:39 am

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
I wish my FTP was FTL.

Who is online

Users browsing this forum: No registered users and 14 guests