Community discussions

MikroTik App
 
User avatar
Vyrtu
newbie
Topic Author
Posts: 45
Joined: Thu Oct 03, 2013 11:49 am
Location: Torrelavega,Spain

Mikrotik script how to line break

Mon Nov 18, 2013 6:02 pm

Hi, i have this script:

ros code

:if ([/ping address=8.8.8.8 count=25]=25)  do={

/file set miconexion.txt contents [/system clock get date]

} else={/file set miconexion.txt contents [/system clock get date]}
I need line break for each script run like that:
nov/18/2013
nov/18/2013
nov/18/2013
nov/18/2013

And this script only replace the first line for each run..
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Mikrotik script how to line break

Mon Nov 18, 2013 6:23 pm

You need to explicitly add to the contents, rather than replace it. Use the "/file" menu's "get" command to get the current contents.

i.e.

ros code

/file set miconexion.txt contents ([/file get miconexion.txt contents] . "\n" . [/system clock get date])
 
User avatar
Vyrtu
newbie
Topic Author
Posts: 45
Joined: Thu Oct 03, 2013 11:49 am
Location: Torrelavega,Spain

Re: Mikrotik script how to line break

Mon Nov 18, 2013 6:56 pm

You need to explicitly add to the contents, rather than replace it. Use the "/file" menu's "get" command to get the current contents.

i.e.

ros code

/file set miconexion.txt contents ([/file get miconexion.txt contents] . "\n" . [/system clock get date])
NICE! The script works, now i need to write a string, i have this:

ros code

:if ([/ping address=8.8.8.8 count=25]=25)  do={

/file set miconexion.txt contents ([/file get miconexion.txt contents] . "\n" . [/system clock get date] . "\_" . [/system clock get time] ."\_ ". "Conexion" . )

} else={/file set miconexion.txt contents [/system clock get date]}
How i can write strings?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Mikrotik script how to line break

Mon Nov 18, 2013 7:01 pm

How i can write strings?

ros code

"Conexion"
is a string...

So... you know... just change it to whatever you want to write. In the case of the above, you've written the word Conexion.
 
User avatar
Vyrtu
newbie
Topic Author
Posts: 45
Joined: Thu Oct 03, 2013 11:49 am
Location: Torrelavega,Spain

Re: Mikrotik script how to line break

Tue Nov 19, 2013 10:27 am

Nice it's working now, i put the final script, if somebody needs it:

ros code

:if ([/ping address=8.8.8.8 count=25]=25)  do={

/file set miconexion.txt contents ([/file get miconexion.txt contents] . "\n" . [/system clock get date] . "\_" . [/system clock get time] ."\_ ". "Conexion")

} else={/file set miconexion.txt contents [/system clock get date]}

pd: The script didnt run before because i didnt need the last concat ".. .\_ ". "Conexion" .)"
Last edited by Vyrtu on Wed Nov 27, 2013 11:53 am, edited 1 time in total.
 
User avatar
Vyrtu
newbie
Topic Author
Posts: 45
Joined: Thu Oct 03, 2013 11:49 am
Location: Torrelavega,Spain

Re: Mikrotik script how to line break

Wed Nov 27, 2013 11:25 am

Hi again guys, i have a little problem with this script, this is the final code:

ros code

:if ([/ping address=8.8.8.8 count=4]=4)  do={

/file set miconexion.rsc contents ([/file get miconexion.rsc contents] . "\n" . [/system clock get date] . "\_" . [/system clock get time] ."\_ ". "Conexion")

} else={/file set miconexion.rsc contents ("\n" . [/system clock get date] . "\_" . [/system clock get time] ."\_". "No hay conexion")}
So, i have this script in a scheduler, every 5 seconds for testing, but i dont know why, this script stop writing in the file or it rewrites the file, erasing all before lines wrote, after X seconds.. :S
Maybe the problem is on the else, but i dont find it..

UPDATE: The script usually stops when the file (miconexion.rsc) reached the +-4000B
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Mikrotik script how to line break

Wed Nov 27, 2013 1:20 pm

Yeah, sadly it's a known issue with RouterOS... The upper limit is really 4096B (or 4KiB).

The only way to keep a larger file is to simply not use scripting to write it and/or store it. Like, you could perhaps use "/tool fetch" to send the results to an FTP or HTTP server, where the contents would be written on a file there.

"But what about when there's no connection to the server?" I hear you asking. Well, you could keep a file on the router up until the server is reachable, and as soon as the connection is back on, send the file's contents, and remove it.
 
User avatar
vklpt
newbie
Posts: 36
Joined: Mon Feb 18, 2019 1:13 pm
Location: Izhevsk
Contact:

Re: Mikrotik script how to line break

Fri Mar 12, 2021 2:19 pm

For Python: try to replace '\n' with '\r\n'

Who is online

Users browsing this forum: No registered users and 19 guests