Page 1 of 1

help in writing file

Posted: Tue Apr 15, 2014 9:38 am
by obadaabdullah
i'v got this script :

:foreach tmpI in=[/ip hotspot user find where (limit-bytes-total > 0)] do={
:local tmpName value=[/ip hotspot user get $tmpI value-name=name];
:local tmpLimitTotal value=[/ip hotspot user get $tmpI value-name=limit-bytes-total];
:local tmpIn value=[/ip hotspot user get $tmpI value-name=bytes-in];
:local tmpOut value=[/ip hotspot user get $tmpI value-name=bytes-out];
:local tmpRemaining value=($tmpLimitTotal - ($tmpIn + $tmpOut));
:local tmpMessage value=("User: ".$tmpName.", Limit Total: ".$tmpLimitTotal.", Used In: ".$tmpIn.", Used Out: ".$tmpOut.", Remaining Total:".$tmpRemaining);
:if ([/ip hotspot user get $tmpI value-name=disabled]) do={:set tmpMessage value=("USER DISABLED: ".$tmpMessage);};
:if ($tmpRemaining < 1) do={:set tmpMessage value=("USER OUT OF BYTES: ".$tmpMessage);};
:log info message=$tmpMessage;
/file set x.txt contents=$tmpMessage
}

the result on log is great
but i get only the last value in my txt file
what to do to write every value in on line in my txt file??

Re: help in writing file

Posted: Tue Apr 15, 2014 10:17 am
by rextended
It's one of my script posted on this forum... :lol:
http://forum.mikrotik.com/viewtopic.php?f=9&t=83813

The file contents is limited to 4096 byte. You not easy get help because existing this limit. STOP.

If this limit are not a problem for you: you can not redefine the contents of file, if you not previously add the old content:
:foreach tmpI in=[/ip hotspot user find where (limit-bytes-total > 0)] do={
:local tmpName value=[/ip hotspot user get $tmpI value-name=name];
:local tmpLimitTotal value=[/ip hotspot user get $tmpI value-name=limit-bytes-total];
:local tmpIn value=[/ip hotspot user get $tmpI value-name=bytes-in];
:local tmpOut value=[/ip hotspot user get $tmpI value-name=bytes-out];
:local tmpRemaining value=($tmpLimitTotal - ($tmpIn + $tmpOut));
:local tmpMessage value=("User: ".$tmpName.", Limit Total: ".$tmpLimitTotal.", Used In: ".$tmpIn.", Used Out: ".$tmpOut.", Remaining Total:".$tmpRemaining);
:if ([/ip hotspot user get $tmpI value-name=disabled]) do={:set tmpMessage value=("USER DISABLED: ".$tmpMessage);};
:if ($tmpRemaining < 1) do={:set tmpMessage value=("USER OUT OF BYTES: ".$tmpMessage);};
:log info message=$tmpMessage;
/file set x.txt contents=([/file get x.txt contents]."\r\n".$tmpMessage);
}

Re: help in writing file

Posted: Tue Apr 15, 2014 11:47 pm
by obadaabdullah
It's one of my script posted on this forum... :lol:
http://forum.mikrotik.com/viewtopic.php?f=9&t=83813

The file contents is limited to 4096 byte. You not easy get help because existing this limit. STOP.

If this limit are not a problem for you: you can not redefine the contents of file, if you not previously add the old content:
:foreach tmpI in=[/ip hotspot user find where (limit-bytes-total > 0)] do={
:local tmpName value=[/ip hotspot user get $tmpI value-name=name];
:local tmpLimitTotal value=[/ip hotspot user get $tmpI value-name=limit-bytes-total];
:local tmpIn value=[/ip hotspot user get $tmpI value-name=bytes-in];
:local tmpOut value=[/ip hotspot user get $tmpI value-name=bytes-out];
:local tmpRemaining value=($tmpLimitTotal - ($tmpIn + $tmpOut));
:local tmpMessage value=("User: ".$tmpName.", Limit Total: ".$tmpLimitTotal.", Used In: ".$tmpIn.", Used Out: ".$tmpOut.", Remaining Total:".$tmpRemaining);
:if ([/ip hotspot user get $tmpI value-name=disabled]) do={:set tmpMessage value=("USER DISABLED: ".$tmpMessage);};
:if ($tmpRemaining < 1) do={:set tmpMessage value=("USER OUT OF BYTES: ".$tmpMessage);};
:log info message=$tmpMessage;
/file set x.txt contents=([/file get x.txt contents]."\r\n".$tmpMessage);
}
thanks
yeh it's your answer and i asked you there but you didn't answer ... see it again