среда, 6 мая 2015 г.

Выводим параметры беспроводного интерфейса в файл, если файл больше 4096 байт записываем данные в следующий файл (wireless-interface1, wireless-interface2, etc...)

# Do not include '.rsc', it is appended automatically
:local filename "wireless-interface"
# Internal processing below...
# ----------------------------------
:local line
:local contents
:local fileindex 1
:local findindex
:local property
:local value
/interface wireless {
   :set contents "/interface wireless\n"
# loop through wireless interfaces, getting their advanced (plus basic) settings
   :foreach r in=[print advanced as-value] do={
      :set line ""
      :foreach i in=[:toarray $r] do={
         :set findindex [:find [:tostr $i] "="]
         :set property [:pick [:tostr $i] 0 $findindex]
         :set value [:pick [:tostr $i] ($findindex + 1) [:len [:tostr $i]]]
#      do not include '.id' property, it will be different on other routers
#      do not include interface-'type' property, it is read-only
         :if ([:tostr $property] = ".id" || \
               [:tostr $property] = "interface-type") do={
            :set property ""
            :set value ""
         }
#      put quotes around comment property
#      put quotes around value if it contains spaces
         :if ([:tostr $property] = "comment" || \
               [:len [:find [:tostr $value] " "]] > 0) do={
            :set value ("\"" . $value . "\"")
         }
#      append property=value to line
         :if ([:len $property] > 0 && [:len $value] > 0) do={
#         use [find] with mac-address (easier import to other routers)
            :if ([:tostr $property] = "mac-address") do={
               :set line ("[find mac-address=\"" . $value . "\"]" . " " . [:tostr $line])
            } else={
               :set line ([:tostr $line] . $property . "=" . $value . " ")
            }
         }
#   end foreach i
      }
      :set line ("set " . [:tostr $line] . "\n")
#   if contents + line is over filesize limit, write out to file
      :if (([:len [:tostr $contents]] + [:len [:tostr $line]]) > 4096) do={
         /system identity export file=($filename . $fileindex)
#      wait for file to appear (this is needed)
         :while ([:len [/file find name=($filename . $fileindex . ".rsc")]] = 0) do={}
         /file set ($filename . $fileindex . ".rsc") contents=[:tostr $contents]
         :set contents "/interface wireless\n"
         :set fileindex ($fileindex + 1)
      }
#   append line to contents
      :set contents ([:tostr $contents] . [:tostr $line])
   }
# write remaining contents
   :if ([:len $contents] > 0) do={
      /system identity export file=($filename . $fileindex)
#   wait for file to appear (this is needed)
      :while ([:len [/file find name=($filename . $fileindex . ".rsc")]] = 0) do={}
      /file set ($filename . $fileindex . ".rsc") contents=[:tostr $contents]
   }
# /interface wireless
}
Взято с http://forum.mikrotik.com/viewtopic.php?t=40830 

Подписаться на новые статьи.

Комментариев нет:

Отправить комментарий