Here is my code, I did some testing and it seems the code gets stuck in an infinite loop inside the "foreach", on the "else" branch. For some reason, the file just doesn't get created.
Code: Select all
:global ifLastSaved
:local time [:pick [/system/clock/get time] 0 5]
:local day [:pick [/system/clock/get date] 4 6]
:local interfaces "12.1_5g,12.1_ch1,12.2_ch1,12.3_ch6,12.4_ch11,12.5_ch11"
:local ifArr [:toarray $interfaces]
#initialize save time
:if ([:len $ifLastSaved]=0) do={ :set $ifLastSaved [:pick $time 0 2]};
:foreach if in=$ifArr do={
:local data ($time." ".[:len [/caps-man registration-table find interface=$if]])
:local filename ("resziget/" . $if . "/" . $if . "-" . [:pick [/system/clock/get date] 4 6])
#we have to create a new file every few hours because of the 4096 character limit
:if ([:pick $time 0 2] > $ifLastSaved +2) do={
:set $ifLastSaved [:pick $time 0 2]
:set $filename ($filename . "-" . [:pick $time 0 2])
/file print file=$filename
:while ([:len [/file/find name=$filename]] = 0) do={ :delay 100ms }
/file set $filename contents=""
} else={
:set $filename ($filename . "-" . $ifLastSaved)
:if ([:len [/file/find name=$filename]] = 0) do={
/file print file=$filename
:while ([:len [/file/find name=$filename]] = 0) do={ :delay 100ms }
}
}
#this part returns "no such item"
/file set $filename contents=([get $filename contents] . $data)
};
If anyone could point out why this happens and how can I fix it, I would be really thankful. I've spent the last few hours testing and tweaking the code and I just can't seem to make any progress.
Edit: I want to run a scheduler with this script. This script would iterate over my CAPs interfaces and extract the number of connected clients from each one. Then it would put the information in a file. We'd add new info at the end of the file for a while (3 hours currently), then we'd create a new file because of the 4096 character limit I heard about. For some reason, the file creation fails. The while-delay loops are supposed to prevent attempting to set a file before it is created. I tried without them, but that also doesn't seem to work.