Script Hotspot Password Daily using preset values

Looking for some assistance to finish off this script, I have used a portion of the calculate days of the week script from another post.

The goal.
Schedule a password change of user1 everyday based on the day of the week.
i.e
Monday = Password2
Friday = Password6

The script determines today day of the week, once the day has been determine, it will change the password to the preset variable password from 1 - 7

I have created this so far but I am not sure how to complete it as it does not work.

Thank You

:do {
###############################
#Determine the day of the week#
###############################
:local sunday “Password1”
:local monday “Password2”
:local tuesday “Password3”
:local wednesday “Password4”
:local thursday “Password5”
:local friday “Password6”
:local saturday “Password7”
###############################
#Determine the day of the week#
###############################
:local date [/system clock get date]
:global result “”
:local months [:toarray “jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec”]
:local monthtbl [:toarray “0,3,3,6,1,4,6,2,5,0,3,5”]
:local daytbl [:toarray “sun,mon,tue,wed,thu,fri,sat”]
:local month [:pick $date 0 3]
:local day [:pick $date 4 6]
:local dayc [:pick $date 5 6]
:local century [:pick $date 7 9]
:local year [:pick $date 9 11]
:local yearc [:pick $date 10 11]
:if ([:pick $date 4 5] = 0) do={ :set day ($dayc)}
:if ([:pick $date 9 10] = 0) do={:set year ($yearc)}
:local sum 0
:set sum ($sum + (2 * (3 - ($century - (($century / 4) * 4)))))
:set sum ($sum + ($year / 4))
:set sum ($sum + $year + $day)
:for mindex from=0 to=[:len $months] do={
:if ([:pick $months $mindex] = $month) do={:set sum ($sum + [:pick $monthtbl $mindex]) }}
:set sum (($sum - (($sum / 7) * 7)))
:set result [:pick $daytbl $sum]
:put ($date . " is on a " . $result)
#######################################################################
#Using IF statements, check the result for matches and change password#
#######################################################################
:if ($result = “sun”) do {
/ip hotspot user set user1 password=$sunday;
:if ($result = “mon”) do={
/ip hotspot user set user1 password=$monday;
:if ($result = “tue”) do={
/ip hotspot user set user1 password=$tuesday;
:if ($result = “wed”) do={
/ip hotspot user set user1 password=$wednesday;
:if ($result = “thu”) do={
/ip hotspot user set user1 password=$thursday;
:if ($result = “fri”) do={
/ip hotspot user set user1 password=$friday;
:if ($result = “sun”) do={
/ip hotspot user set user1 password=$saturday;}}

I think the problem is in your :if statements. They all need to have a starting bracket { and an ending one }

Also, the first :if statement is missing the = sign after the word “do” like the other ones.

HTH

I didn’t check the top part, but your if statements had issues.
###############################
#Determine the day of the week#
###############################
:local sunday “Password1”
:local monday “Password2”
:local tuesday “Password3”
:local wednesday “Password4”
:local thursday “Password5”
:local friday “Password6”
:local saturday “Password7”
###############################
#Determine the day of the week#
###############################
:local date [/system clock get date]
:global result “”
:local months [:toarray “jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec”]
:local monthtbl [:toarray “0,3,3,6,1,4,6,2,5,0,3,5”]
:local daytbl [:toarray “sun,mon,tue,wed,thu,fri,sat”]
:local month [:pick $date 0 3]
:local day [:pick $date 4 6]
:local dayc [:pick $date 5 6]
:local century [:pick $date 7 9]
:local year [:pick $date 9 11]
:local yearc [:pick $date 10 11]
:if ([:pick $date 4 5] = 0) do={ :set day ($dayc)}
:if ([:pick $date 9 10] = 0) do={:set year ($yearc)}
:local sum 0
:set sum ($sum + (2 * (3 - ($century - (($century / 4) * 4)))))
:set sum ($sum + ($year / 4))
:set sum ($sum + $year + $day)
:for mindex from=0 to=[:len $months] do={
:if ([:pick $months $mindex] = $month) do={:set sum ($sum + [:pick $monthtbl $mindex]) }}
:set sum (($sum - (($sum / 7) * 7)))
:set result [:pick $daytbl $sum]
:put ($date . " is on a " . $result)
#######################################################################
#Using IF statements, check the result for matches and change password#
#######################################################################
/ip hotspot user {
:if ($result = “sun”) do {
set user1 password=$sunday;
}

:if ($result = “mon”) do={
    set user1 password=$monday;
}

:if ($result = “tue”) do={
    set user1 password=$tuesday;
}

:if ($result = “wed”) do={
    set user1 password=$wednesday;
}

:if ($result = “thu”) do={
    user set user1 password=$thursday;
}

:if ($result = “fri”) do={
    set user1 password=$friday;
} else={
    set user1 password=$saturday;
}

}

I didn’t realize until just now that in the original code there are two :if ($result = “sun”) blocks, which efaden fixed. However, I think the following code will cause issues. If today is “fri”, the password will be set correctly. Any other day (mon,tues,etc) will get the “sat” password.
:if ($result = “fri”) do={
set user1 password=$friday;
} else={
set user1 password=$saturday;
}Should be:
:if ($result = “fri”) do={
set user1 password=$friday;
}
:if ($result = “sat”) do={
set user1 password=$saturday;
}

Your right. Forgot there isn’t a good else if on router os

Sent from my SCH-I545 using Tapatalk

Should be
###############################
#Determine the day of the week#
###############################
:local sunday “Password1”
:local monday “Password2”
:local tuesday “Password3”
:local wednesday “Password4”
:local thursday “Password5”
:local friday “Password6”
:local saturday “Password7”
###############################
#Determine the day of the week#
###############################
:local date [/system clock get date]
:global result “”
:local months [:toarray “jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec”]
:local monthtbl [:toarray “0,3,3,6,1,4,6,2,5,0,3,5”]
:local daytbl [:toarray “sun,mon,tue,wed,thu,fri,sat”]
:local month [:pick $date 0 3]
:local day [:pick $date 4 6]
:local dayc [:pick $date 5 6]
:local century [:pick $date 7 9]
:local year [:pick $date 9 11]
:local yearc [:pick $date 10 11]
:if ([:pick $date 4 5] = 0) do={ :set day ($dayc)}
:if ([:pick $date 9 10] = 0) do={:set year ($yearc)}
:local sum 0
:set sum ($sum + (2 * (3 - ($century - (($century / 4) * 4)))))
:set sum ($sum + ($year / 4))
:set sum ($sum + $year + $day)
:for mindex from=0 to=[:len $months] do={
:if ([:pick $months $mindex] = $month) do={:set sum ($sum + [:pick $monthtbl $mindex]) }}
:set sum (($sum - (($sum / 7) * 7)))
:set result [:pick $daytbl $sum]
:put ($date . " is on a " . $result)
#######################################################################
#Using IF statements, check the result for matches and change password#
#######################################################################
/ip hotspot user {
:if ($result = “sun”) do {
set user1 password=$sunday;
}

:if ($result = “mon”) do={
    set user1 password=$monday;
}

:if ($result = “tue”) do={
    set user1 password=$tuesday;
}

:if ($result = “wed”) do={
    set user1 password=$wednesday;
}

:if ($result = “thu”) do={
    user set user1 password=$thursday;
}

:if ($result = “fri”) do={
    set user1 password=$friday;
} 

:if ($result = "sat") do={
    set user1 password=$saturday;
}

}