Community discussions

MikroTik App
 
User avatar
hecklertm
Member Candidate
Member Candidate
Topic Author
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

weird results when pasting a long script on cmd line

Wed Apr 12, 2006 5:20 am

I have had the worst time with trying to design scripts by slowly building the script on the command line and as copy and pasting the elements I want to use into a "notepad" text file, and then once I have the whole thing the way I want it, I paste it all at once into the "source" field of a script or try to paste in the new script entry as you will see below. I will give you an example. When I paste the command:
/system script add name=ebackup source={/system backu
p save name=([/system identity get name] . "-" . [:pick [/system clock get date] 7 11] . 
[:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6]); /tool e-mai
l send to="routerbackup@hypewifi.com" subject=([/system identity get name] . " Backup " .
 [/system clock get date]) file=([/system identity get name] . "-" . [:pick [/system cloc
k get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date
] 4 6] . ".backup"); :delay 10; /file rem [/file find name=([/system identity get name] .
 "-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:p
ick [/system clock get date] 4 6] . ".backup")]}
it comes out of notepad looking just like you see above. Mind you, this is ONE line of code not multiple lines, but it pastes in as if it is seperate lines of code. Are there hidden characters I can't see? I thought notepad was just "clear text" so I would not have hidden \n and things like that.

Now what's even worse is that if I try to go edit this script using the script editor in MT, it shows up as several lines of wrapped text instead of one line of code. When I use the backspace key to combine the text betweeen 2 lines, the editor goes crazy and the cursor flys all over the screen and I am unable to recover the session. And, if I log out to of the router and try to ssh in again, I do not even get a command prompt, it just hangs after it shows the mikrotik logo and the os version. I am using 2.9.18. I am now physically going to the routers to power cycle them so that I will hopefully get back into them.

Please advise if you have any knowledge of this problem.
 
User avatar
hecklertm
Member Candidate
Member Candidate
Topic Author
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Wed Apr 12, 2006 5:48 am

Obviously, this shows that I am a total novice when it comes to the scripting. I would like to add that when I pasted the code below into the window so that you could read it, it would break itself up incorrectly.

But, I tested if I paste the code in and then manually removed all of the extra "breaks", and then copied it back to notepad, that new block of code was fine and did not have the invisible breaks in it anymore.

In notepad, it looks the same either way... I will paste both lines so that you see the difference. Remember, in notepad, both of these line look IDENTICAL, but when I paste them here you see the difference.

1) The line which has never been pasted here before.
/system script add name=ebackup source={/system backu
p save name=([/system identity get name] . "-" . [:pick [/system clock get date] 7 11] . 
[:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6]); /tool e-mai
l send to="routerbackup@hypewifi.com" subject=([/system identity get name] . " Backup " .
 [/system clock get date]) file=([/system identity get name] . "-" . [:pick [/system cloc
k get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date
] 4 6] . ".backup"); :delay 10; /file rem [/file find name=([/system identity get name] .
 "-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:p
ick [/system clock get date] 4 6] . ".backup")]}
2) The line which was pasted in this window (extra linefeeds removed while in this window) and then pasted back into notepad. Then pasted again from notpad back to here successfully.
/system script add name=ebackup source={/system backup save name=([/system identity get name] . "-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6]); /tool e-mail send to="routerbackup@hypewifi.com" subject=([/system identity get name] . " Backup " . [/system clock get date]) file=([/system identity get name] . "-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . ".backup"); :delay 10; /file rem [/file find name=([/system identity get name] . "-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . ".backup")]}
Is notepad hiding line feeds? I know where these line feeds came from. They were added somehow when I was testing peices of this script in the router and when I got it the way I liked it, I would copy it from the router to notepad on my computer so that I could log into other routers and paste it.

So I guess my final problem is two fold.

1) I guess I should never copy multiline output from the router into a notepad file to save for later use since hidden linefeeds are copied over with the visible text.
2) Why does the script editor freak out and lock me out of the router when I try to combine the multiple lines by pressing backspace to delete one of these invisible characters.
 
User avatar
hecklertm
Member Candidate
Member Candidate
Topic Author
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Sun Apr 30, 2006 6:52 am

I never recieved feedback from the MT guys on the problem with the editor inside of MT causing the console to "freak out" if you use the backspace key to delete a <cr> and merge two lines together into one line.

What its the problem? I have had this problem ever since I first used the edit command in 2.9.10 (I assume it was there before then) and it still does the same thing in 2.9.23 today. It is very annoying, because the only way to get the console back is to manually power reset the router.

Please advise MT!
 
User avatar
hecklertm
Member Candidate
Member Candidate
Topic Author
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Tue May 02, 2006 4:39 am

Any MT guys see this post???

Is this an old issue that everybody already deals with and does not care? Should I not bother trying to use the built in editor and just edit long strings on my own computer instead? :wink:
 
eflanery
Member
Member
Posts: 376
Joined: Fri May 28, 2004 10:11 pm
Location: Moscow, ID
Contact:

Tue May 02, 2006 8:31 pm

For one, I would advise against trying to fit all your code on one line.

In addition to being more like to bring out bugs, long lines make the code practically unreadable, and will seriously hamper your debugging efforts.

By a quick glance at your script, you may find this useful: http://forum.mikrotik.com/viewtopic.php?t=6774

--Eric
 
User avatar
hecklertm
Member Candidate
Member Candidate
Topic Author
Posts: 165
Joined: Fri Jun 24, 2005 5:12 am
Location: US

Tue May 02, 2006 8:43 pm

Thanks for your feedback eflanery. Not to seem rude, esp. since I will see you guys Thurs and Fri, but...

1) Breaking out the code to multiple lines for human purposes is not a solution to the editor bug, that is a work around. If I was looking for codeing recommendations, I would have broke it out for human reading purposes.

2) My code does not need to be debugged, it works just fine.

3) The post you mentioned may have been helpful would I still have been building my code, yet I was done several weeks ago.


So, once again, (MT employees) please address the problem with the editor. Is it something that will be fixed or should we discontinue editing long strings with the editor. The editor not working properly is definitely not the end of the world, but it would be nice to know.
 
eflanery
Member
Member
Posts: 376
Joined: Fri May 28, 2004 10:11 pm
Location: Moscow, ID
Contact:

Wed May 03, 2006 3:10 am

Thanks for your feedback eflanery. Not to seem rude, esp. since I will see you guys Thurs and Fri, but...
No offence taken, and none intended.
1) Breaking out the code to multiple lines for human purposes is not a solution to the editor bug, that is a work around. If I was looking for codeing recommendations, I would have broke it out for human reading purposes.
It seems to me, that by squishing everything together on a single line, you are creating something of an edge case. If there is a bug, it should (and hopefully will) be fixed; but I doubt anyone at MT was thinking about 400 character lines, when designing the editor.
2) My code does not need to be debugged, it works just fine.
Just don't run it too close to midnight. :)

--Eric

Who is online

Users browsing this forum: Google [Bot], GoogleOther [Bot] and 10 guests