Joziff
December 7, 2010, 7:42pm
1
Hello,
I have one big problem and it is that when I run my script manually everything is OK but if I use a scheduler it is bad, but yesterday I tried it and scheduler went good.
I paste a code script here:
:local MAC ""
:local clientcount [:len [/interface wireless registration-table find]]
:local count 0
:local value ""
:local findindex 0
:if ($clientcount > 0) do={
:for i from=0 to=($clientcount - 1) step=1 do={
:set count 0
:set MAC [/interface wireless registration-table get number=$i value-name=mac-address]
:set value [/interface wireless registration-table get number=$i value-name=bytes]
:if ([:len ($value . "\n")] < ([/system resource get free-hdd-space] * 1024)) do={
:while ([:len [/file find name=("BytesMAC" . $count . "-" . $MAC . ".txt")]] = 1) do={
:set count ($count + 1)
}
:if ($count = 0) do={
/file print file=("BytesMAC0-" . $MAC)
:while ([:len [/file find name=("BytesMAC0-" . $MAC . ".txt")]] = 0) do={}
/file set ("BytesMAC0-" . $MAC . ".txt") contents=""
:set count ($count + 1)
}
:if ([:len ([/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents] . $value . "\n")] > 4096) do={
/file print file=("BytesMAC" . $count . "-" . $MAC)
:while ([:len [/file find name=("BytesMAC" . $count . "-" . $MAC . ".txt")]] = 0) do={}
/file set ("BytesMAC" . $count . "-" . $MAC . ".txt") contents=""
/file set ("BytesMAC" . $count . "-" . $MAC . ".txt") contents=($value . "\n")
} else={
/file set ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents=([/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents] . $value . "\n")
}
}
#next i
}
#endif
}
It should check if there is any client joined to AP, then get its MAC-address and bytes Rx,Tx and find file named “BytesMACi-macaddr” or create one and write bytes to it. Could u help me?
janisk
December 8, 2010, 1:09pm
2
ypi can try to add this as a script and run script from scheduler, that is, if you are not doing that already.
Joziff
December 8, 2010, 4:34pm
3
I have this in script and then using scheduler to run this script every 5 second but after a some time it stops or the script no run so I think that the problem is that it gets bad count of items in reg table. I paste all code here so u may check if there is no error somewhere:
:local MAC ""
:local clientcount [:len [/interface wireless registration-table find]]
:local count 0
:local countrtx 0
:local value ""
:local findindex 0
:local Rx 0
:local Tx 0
:local RxTx ""
:local deltaRx 0
:local deltaTx 0
:local n 1
:if ($clientcount > 0) do={
:for i from=0 to=($clientcount - 1) step=1 do={
:set count 0
:set MAC [/interface wireless registration-table get number=$i value-name=mac-address]
:set value [/interface wireless registration-table get number=$i value-name=bytes]
:if (($MAC !="") && ($value !="")) do={
:set findindex [:find $value ","]
:set Rx [:pick $value 0 $findindex]
:set Tx [:pick $value ($findindex + 1) [:len $value]]
:if ([/system resource get free-hdd-space] > 2048) do={
:while ([:len [/file find name=("BytesMAC" . $count . "-" . $MAC . ".txt")]] = 1) do={
:set count ($count + 1)
}
:if ($count = 0) do={
/file print file=("BytesMAC0-" . $MAC)
:while ([:len [/file find name=("BytesMAC0-" . $MAC . ".txt")]] = 0) do={}
/file set ("BytesMAC0-" . $MAC . ".txt") contents=$value
} else={
:if ([:len ("\n" . [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents] . $value)] > 4096) do={
/file print file=("BytesMAC" . $count . "-" . $MAC)
:while ([:len [/file find name=("BytesMAC" . $count . "-" . $MAC . ".txt")]] = 0) do={}
/file set ("BytesMAC" . $count . "-" . $MAC . ".txt") contents=$value
:while ((([:len [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents]] - $n) >= 0) && ([:pick [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents] ([:len [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents]] - $n) 1] != "\n")) do={
:set n ($n + 1)
}
:set RxTx [:pick [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents] ([:len [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents]] - ($n - 1)) [:len [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents]]]
:set findindex [:find $RxTx ","]
:set deltaRx [:pick $RxTx 0 $findindex]
:set deltaTx [:pick $RxTx ($findindex + 1) [:len $RxTx]]
:while ([:len [/file find name=("RxTx" . $countrtx . "-" . $MAC . ".txt")]] = 1) do={
:set countrtx ($countrtx + 1)
}
:if ($countrtx = 0) do={
/file print file=("RxTx0-" . $MAC)
:while ([:len [/file find name=("RxTx0-" . $MAC . ".txt")]] = 0) do={}
/file set ("RxTx0-" . $MAC . ".txt") contents=(($Rx - $deltaRx) . "," . ($Tx - $deltaTx))
} else={
:if ([:len ("\n" . [/file get ("RxTx" . ($countrtx - 1) . "-" . $MAC . ".txt") contents] . (($Rx - $deltaRx) . "," . ($Tx - $deltaTx)))] > 4096) do={
/file print file=("RxTx" . $countrtx . "-" . $MAC . ".txt")
:while ([:len [/file find name=("RxTx" . $countrtx . "-" . $MAC . ".txt")]] = 0) do={}
/file set ("RxTx" . $countrtx . "-" . $MAC . ".txt") contents=(($Rx - $deltaRx) . "," . ($Tx - $deltaTx))
} else={
/file set ("RxTx" . ($countrtx - 1) . "-" . $MAC . ".txt") contents=([/file get ("RxTx" . ($countrtx - 1) . "-" . $MAC . ".txt") contents] . "\n" . ($Rx - $deltaRx) . "," . ($Tx - $deltaTx))
}
}} else={
:while ((([:len [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents]] - $n) >= 0) && ([:pick [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents] ([:len [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents]] - $n)] != "\n")) do={
:set n ($n + 1)
}
:set RxTx [:pick [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents] ([:len [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents]] - ($n - 1)) [:len [/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents]]]
:set findindex [:find $RxTx ","]
:set deltaRx [:pick $RxTx 0 $findindex]
:set deltaTx [:pick $RxTx ($findindex + 1) [:len $RxTx]]
/file set ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents=([/file get ("BytesMAC" . ($count - 1) . "-" . $MAC . ".txt") contents] . "\n" . $value)
:while ([:len [/file find name=("RxTx" . $countrtx . "-" . $MAC . ".txt")]] = 1) do={
:set countrtx ($countrtx + 1)
}
:if ($countrtx = 0) do={
/file print file=("RxTx0-" . $MAC)
:while ([:len [/file find name=("RxTx0-" . $MAC . ".txt")]] = 0) do={}
/file set ("RxTx0-" . $MAC . ".txt") contents=(($Rx - $deltaRx) . "," . ($Tx - $deltaTx))
} else={
:if ([:len ("\n" . [/file get ("RxTx" . ($countrtx - 1) . "-" . $MAC . ".txt") contents] . (($Rx - $deltaRx) . "," . ($Tx - $deltaTx)))] > 4096) do={
/file print file=("RxTx" . $countrtx . "-" . $MAC . ".txt")
:while ([:len [/file find name=("RxTx" . $countrtx . "-" . $MAC . ".txt")]] = 0) do={}
/file set ("RxTx" . $countrtx . "-" . $MAC . ".txt") contents=(($Rx - $deltaRx) . "," . ($Tx - $deltaTx))
} else={
/file set ("RxTx" . ($countrtx - 1) . "-" . $MAC . ".txt") contents=([/file get ("RxTx" . ($countrtx - 1) . "-" . $MAC . ".txt") contents] . "\n" . ($Rx - $deltaRx) . "," . ($Tx - $deltaTx))
}
}
}
}
} else={
/system scheduler disable cons
}
}
#next i
}
#endif
}
janisk
December 9, 2010, 2:06pm
4
are you sure that your script is done in 5 seconds?
edit:
also, could you try to explain what and why you are doing with this script?
Joziff
December 11, 2010, 2:08pm
5
Sure. This script checks for items in wireless reg-table. If there is 1 or more clients it starts with getting mac-address and bytes value of first and saves it into 2 files. First file contains value-type bytes , second one contains algebraical difference between new value and last value. If file does not exist its created. Also is created if contents length is longer then 4096 bytes.
Problem is that I must save value type bytes and then find character “,” because number before means received packets size and after it transmited packets size so I cant make differce between them.
If there is any possibility how to get only Rx packets size or Tx packets size tell me.
Thanks much for help.