Need help in array!

Goal is to get the array value based on date month.

Thanks

:local date [/system clock get date];
:local months {jan="africa";feb="brazil";mar="canada";apr="denmark";may="egypt";jun="france";jul="germany";aug="holland";sep="india";oct="japan";nov="kenya";dec="laos"};
:local month ($months->[:pick $date 0 3] );

:local month (:if ($months->[:pick $date 0 3]) );
:local newPassword ($month);


:log info ($date)
:log info ($months)
:log info ($month)
:log info ($newPassword)
:log info ([ [:tostr ($month)]] );

So far i’m getting this output;
https://forum.mikrotik.com/download/file.php?mode=view&id=43467
vv.png

With

:local month ($months->[:pick $date 0 3] );

you are correctly obtaining the content of the array. The problem is the :if statement.

If I’m right, what you are trying to do is check if the month is set and, if so, set $newPassword with the selected value. You can do it like this:

if ([:typeof ($months->[:pick $date 0 3])] != "nothing") do={ :local newPassword ($months->[:pick $date 0 3]); }

Hi @al3xeezer thanks for your reply, I will try your code. Thank you so much.

I finally got to complete my script thanks to al3xeezer.

This will change your wifi hotspot password based on months.

checks current wifi hotspot password, if true this will not proceed on sending an email report and will not change your password.
if false the script will send the new password into your email and will change the wifi hotspot password based on what month you’re in right now.
just add a scheduler to run this script perfectly :slight_smile:

:local date [/system clock get date];
:local months {jan="africa";feb="brazil";mar="canada";apr="denmark";may="egypt";jun="france";jul="germany";aug="holland";sep="india";oct="japan";nov="kenya";dec="laos"};
if ([:typeof ($months->[:pick $date 0 3])] != "nothing") do={ :global newPassword ($months->[:pick $date 0 3]); 

:local currentPass [/ip hotspot user get bayfront password];
:if ($currentPass = $newPassword) do={
:log info ("Its not time yet to change to ". $currentPass);} else={
:log info ("Monthly wifi hotspot password changed to:  ".$newPassword)
/ip hotspot user set bayfront password="$newPassword";
/tool e-mail send to=your@email.com  subject= ([/system identity get name] . " WiFi Password Changed " . \
[/system clock get date])  body="Bayfront Hotel Cebu Wifi Hotspot Password was Changed to $newPassword
This is a system generated e-mail, sent from Mikrotik RouterOS.

Thank you,
Rey Austine Echavez
Bayfront Hotel Cebu - IT"

}}