Community discussions

MikroTik App
 
n21roadie
Forum Guru
Forum Guru
Topic Author
Posts: 1949
Joined: Fri Aug 07, 2009 10:36 pm
Location: Limerick,Ireland

Testing a script

Tue Dec 20, 2011 8:13 pm

How does one test a script for syntax errors etc, with terminal at least you have a visual indication that a syntax error exists as you type?
 
User avatar
skillful
Trainer
Trainer
Posts: 552
Joined: Wed Sep 06, 2006 1:42 pm
Location: Abuja, Nigeria
Contact:

Re: Testing a script

Tue Dec 20, 2011 10:57 pm

Enclose the script in a parenthesis, then copy and paste it in a terminal window.
 
n21roadie
Forum Guru
Forum Guru
Topic Author
Posts: 1949
Joined: Fri Aug 07, 2009 10:36 pm
Location: Limerick,Ireland

Re: Testing a script

Wed Dec 21, 2011 12:19 am

Enclose the script in a parenthesis, then copy and paste it in a terminal window.
I used before the start of script (( and at the end )) and from terminal, below is a sample of the script
You do not have the required permissions to view the files attached to this post.
 
n21roadie
Forum Guru
Forum Guru
Topic Author
Posts: 1949
Joined: Fri Aug 07, 2009 10:36 pm
Location: Limerick,Ireland

Re: Testing a script

Wed Dec 21, 2011 5:18 pm

Need some advice on how to edit script synatax errors attached is two screenshots of script http://www.mikrotik-routeros.com/?p=24

Both I have at the start #Test one has /n at the start of most lines and the second is with /n removed
You do not have the required permissions to view the files attached to this post.
 
jandafields
Forum Guru
Forum Guru
Posts: 1515
Joined: Mon Sep 19, 2005 6:12 pm

Re: Testing a script

Thu Dec 22, 2011 4:22 am

The page you got that script from is all messed up with /n and /r and linebreaks... all those things should not be in there, and they are showing up because that other page is formatted very badly.

Remove all of the /n /r and line breaks that don't belong.
 
n21roadie
Forum Guru
Forum Guru
Topic Author
Posts: 1949
Joined: Fri Aug 07, 2009 10:36 pm
Location: Limerick,Ireland

Re: Testing a script

Thu Dec 22, 2011 2:20 pm

The page you got that script from is all messed up with /n and /r and linebreaks... all those things should not be in there, and they are showing up because that other page is formatted very badly.

Remove all of the /n /r and line breaks that don't belong.
Many thanks for you reply, as you tell from my questions my present knowledge of scripting is limited (?)- if i remove the \r\ and \n, will this cause the script not to run?

I tried this script (from http://www.mikrotik-routeros.com/?p=24)

I am testing this script correctly in terminal? - In bold is the section i am getting syntax error's the start and beyond this section appears to be OK?

#Test
/system scheduler
add comment="" disabled=no interval=1h name=Overseer on-event="/system script run overseer" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive start-date=jan/01/1970 start-time=00:30:00
/system script
add name=overseer policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source=":global found\r\
\n:global mailserver\r\
\n:global adminaddress\r\
\n:global fromaddress\r\
\n:local isfqdn\r\
\n\r\
\n##################\r\
\n# User editable Variables #\r\
\n##################\r\
\n\r\
\n# Set all mail variables each time script is run - you should update these details from this script only\r\
\n# Note you can use a dns name for the mailserver however if for any reason this name does not resolve the script will terminate. This is a known bug in 3.X and 4.X\r\
\n\r\
\n:set mailserver \"mail.domain.tld\"\r\
\n\r\
\n# Is the value above a valid domain name (no if IP address)\r\
\n:set isfqdn \"yes\"\r\
\n\r\
\n:set adminaddress \"example@domain.tld<script type=text/javascript\"
(/* <![CDATA[ */ (function(){try{var s,a,i,j,r,c,l=document.getElementById(__cf_email__);a=l.className;if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})(); /* ]]> */ </script>\"\r\
\n\r\
\n:set fromaddress \"example@domain.tld<script type=text/javascript"\r\
\n\r\
(\n/* <![CDATA[ */ (function(){try{var s,a,i,j,r,c,l=document.getElementById("__cf_email__");a=l.className;if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})(); /* ]]> */ </script>\"\r\
\n\r\
\n######################\r\
\n# End of user editible variables #\r\
\n######################\r\
\n\r\
\n:if ([\$isfqdn] = \"yes\") do={:set mailserver [:resolve \$mailserver]}\r\
\n\r\

\n/system script run monthend\r\
\n\r\
\n:if ([\$found] = \"true\") do={/system script run monthlyreport; :log info \"--Completed Monthly Report--\"} else={ /system script run usagereport; :log info \"--Completed Usage Report--\"}"

add name=monthend policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source=":local date\r\
\n:local time\r\
\n:local day\r\
\n:local month\r\
\n:local year\r\
\n:local hour\r\
\n:global found \"\"\r\
\n\r\
\n:set date [/system clock get date]\r\
\n:set time [/system clock get time]\r\
\n:set day [:pick \$date 4 6]\r\
\n:set hour [:pick \$time 0 2]\r\
\n\r\
\n:if ([\$day] = \"01\" ) do={ :if ([\$hour] = \"00\" ) do={:set found \"true\" } else={ :set found \"false\" } } else={ :set found \"false\" }"
add name=usagereport policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source=":global mailserver\r\
\n:global adminaddress\r\
\n:global fromaddress\r\
\n:local content\r\
\n:local i\r\
\n:local sitename\r\
\n:local gigs\r\
\n:local email\r\
\n:local megstotal\r\
\n:local totalcurrent\r\
\n:local bytesdowncurrent\r\
\n:local bytesupcurrent\r\
\n:local megsdowncurrent\r\
\n:local megsupcurrent\r\
\n:local percentage\r\
\n:local lastwarning\r\
\n:local warninglevel\r\
\n:local warn\r\
\n:local update\r\
\n:local newwarning\r\
\n:local bytesdownsaved\r\
\n:local bytestotal\r\
\n\r\
\n#Script based on Automated billing script at http://wiki.mikrotik.com/wiki/AutomatedBilling\r\
\n#Details:\r\
\n#This script checks all current simple queues and using values stored in the queue comment will allow you keep track of usage by each site\r\
\n#The details stored in the queue are broken down and used to determine when a user should be sent a usage warning at 50 75 90 and 100%\r\
\n#You can create/modify a new entry as long as you follow this format\r\
\n#1) If you just want to name an entry you may do so like \"XYZ Router\" in the queue name\r\
\n#2) If you want to determine a data limit, enter it like \"sitename!gigabytelimit#emailaddress!00#0000\" into the comment.\r\
\n#3) If you just want to enter a comment on its own, you can do this so long as you don't have an \"!\" in the field\r\
\n#Breaking it down: sitename is a descriptive name, gigabyte limit is the monthy limit, email address is the address you want notified \r\
\n#00 is the last percentage warning level for this user, 0000 is the default value for a new data store\r\
\n#This version created by Andrew Cox - http://www.accessplus.com.au\r\
\n#v1.4 Updated 15/June/2009\r\
\n:log info \"------ Begining Daily Usage Reports -------\"\r\
\n\r\
\n#For each queue in the list\r\
\n:foreach i in=[/queue simple find comment !=\"\"] do={\r\
\n\r\
\n#Pull comment out of queue and divide up accordingly\r\
\n:set content [/queue simple get \$i comment]\r\
\n\r\
\n#Determine variables from comment\r\
\n#Format is: sitename ! gigsallowed # who-to-email ! last warning level(0-50-75-90-99)\r\
\n:if ([:find \$content \"!\"] != \"\") do={\r\
\n :local pos1 [:find \$content \"!\"]\r\
\n :local pos4 [:len \$content]\r\
\n :local pos2 ([:find [:pick \$content (\$pos1+1) \$pos4] \"#\"]+\$pos1+1)\r\
\n :local pos3 ([:find [:pick \$content (\$pos2+1) \$pos4] \"!\"]+\$pos2)\r\
\n :set sitename [:pick \$content 0 (\$pos1)]\r\
\n :set gigs [:pick \$content (\$pos1+1) \$pos2]\r\
\n :set email [:pick \$content (\$pos2+1) (\$pos3+1)]\r\
\n :set totalcurrent [/queue simple get \$i bytes]\r\
\n :set lastwarning [:pick \$content (\$pos3+2) (\$pos3+4)]\r\
\n :local pos5 [:find \$totalcurrent \"/\"]\r\
\n :local pos6 [:len \$totalcurrent]\r\
\n :set bytesupcurrent ([:pick \$totalcurrent 0 (\$pos5)])\r\
\n :set bytesdowncurrent ([:pick \$totalcurrent (\$pos5+1) \$pos6])\r\
\n :set megsupcurrent (\$bytesupcurrent / 1048576)\r\
\n :set bytesdownsaved ([:pick \$content (\$pos3+5) \$pos4])\r\
\n :set bytestotal (\$bytesdowncurrent + \$bytesdownsaved)\r\
\n :set megsdowncurrent (\$bytestotal / 1048576)\r\
\n\r\
\n#Begin calculating usage percentage\r\
\n :set percentage ( ( \$bytestotal * 100) / (\$gigs * 1073741824 ) )\r\
\n :log info \"\$sitename: \$percentage%\"\r\
\n :if ([\$percentage] < 50) do={ :set warninglevel \"00\" }\r\ \n :if ([\$percentage] > 50) do={\r\
\n :if ([\$percentage] < 75) do={ :set warninglevel \"50\" }\r\ \n :if ([\$percentage] > 75) do={ :set warninglevel \"75\" }\r\
\n }\r\
\n :if ([\$percentage] > 75) do={\r\
\n :if ([\$percentage] < 90) do={ :set warninglevel \"75\" }\r\ \n :if ([\$percentage] > 90) do={ :set warninglevel \"90\" }\r\
\n }\r\
\n :if ([\$percentage] > 90) do={\r\
\n :if ([\$percentage] < 100) do={ :set warninglevel \"90\" }\r\ \n :if ([\$percentage] > 100) do={ :set warninglevel \"99\" }\r\
\n }\r\
\n\r\
\n# Parse warning necessity\r\
\n :if ([\$warninglevel] > \$lastwarning ) do={ :set warn \"true\" ; :set update \"true\" }\r\
\n :if ([\$warninglevel] = \$lastwarning ) do={ :set warn \"false\" ; :set update \"false\" }\r\
\n :if ([\$warninglevel] < \$lastwarning ) do={ :set warn \"false\" ; :set update \"true\" }\r\
\n\r\
\n#Update Warning Levels\r\
\n :if ([\$update] = true ) do={ :set newwarning \$warninglevel } else={ :set newwarning \$lastwarning }\r\
\n :if ([\$warn] = true ) do={\r\
\n#Check for email address in queue comment\r\
\n :if ([\$email] != \"\" ) do={\r\
\n /tool e-mail send server=\$mailserver from=\$fromaddress to=\"\$email\" subject=\"\$sitename: Usage at \$percentage\" body=\"This message is to inform you of the current usage for \$sitename\r\
\nThe current warning trigger is \$warninglevel%.\r\
\n\r\
\nThis site has downloaded \$megsdowncurrent MB, which is over \$percentage% of the \$gigs GB monthly download allowance.\r\
\n\r\
\nThis is an Automatically generated E-mail that is sent out when users reach 50%, 75%, 90% and 100% of their cap.\r\
\n\r\
\nTraffic Monitor System,\r\
\n\$fromaddress\"\r\
\n}\r\
\n#Send email to support/accounts also\r\
\n /tool e-mail send server=\$mailserver from=\$fromaddress to=\$adminaddress subject=\"\$sitename: Usage at \$percentage\" body=\"Current usage for \$sitename - trigger is \$warninglevel%.\r\
\n\$megsdowncurrent MB, which is over \$percentage% of the \$gigs GB monthly download allowance.\r\
\nTraffic Monitor System\"\r\
\n:log info \"Sent Warning Level \$warninglevel% to \$email\"\r\
\n}\r\
\n#Set new warning level on queue comment\r\
\n/queue simple set \$i comment=\"\$sitename!\$gigs#\$email!\$newwarning#\$bytestotal\"\r\
\n/queue simple reset-counters \$i\r\
\n}\r\
\n}"
add name=monthlyreport policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source=":global mailserver\r\
\n:global adminaddress\r\
\n:global fromaddress\r\
\n:local content\r\
\n:local i\r\
\n:local sitename\r\
\n:local gigs\r\
\n:local email\r\
\n:local megstotal\r\
\n:local totalcurrent\r\
\n:local bytesdowncurrent\r\
\n:local bytesupcurrent\r\
\n:local megsdowncurrent\r\
\n:local megsupcurrent\r\
\n:local percentage\r\
\n:local bytesdownsaved\r\
\n:local bytesdowntotal\r\
\n\r\
\n#Script based on Automated billing script at http://wiki.mikrotik.com/wiki/AutomatedBilling\r\
\n#This version created by Andrew Cox - http://www.accessplus.com.au\r\
\n#v1.4 Updated 15th June 2009\r\
\n:log info \"------ Begining Monthly Reports -------\"\r\
\n#For each queue in the list\r\
\n:foreach i in=[/queue simple find comment !=\"\"] do={\r\
\n\r\
\n#Pull comment out of queue and divide up accordingly\r\
\n:set content [/queue simple get \$i comment] \r\
\n\r\
\n#Determine variables from comment\r\
\n#Format is: sitename ! gigsallowed # who-to-email ! last warning level(0-50-75-90-100)\r\
\n:if ( [ :find \$content \"!\" ] != \"\" ) do={\r\
\n :local pos1 [:find \$content \"!\"]\r\
\n :local pos4 [:len \$content]\r\
\n :local pos2 ([:find [:pick \$content (\$pos1+1) \$pos4] \"#\"]+\$pos1+1)\r\
\n :local pos3 ([:find [:pick \$content (\$pos2+1) \$pos4] \"!\"]+\$pos2)\r\
\n :set sitename [:pick \$content 0 (\$pos1)]\r\
\n :set gigs [:pick \$content (\$pos1+1) \$pos2]\r\
\n :set email [:pick \$content (\$pos2+1) (\$pos3+1)]\r\
\n :set totalcurrent [/queue simple get \$i bytes]\r\
\n :local pos5 [:find \$totalcurrent \"/\"]\r\
\n :local pos6 [:len \$totalcurrent]\r\
\n :set bytesupcurrent ([:pick \$totalcurrent 0 (\$pos5)])\r\
\n :set bytesdowncurrent ([:pick \$totalcurrent (\$pos5+1) \$pos6])\r\
\n :set megsupcurrent (\$bytesupcurrent / 1048576)\r\
\n :set bytesdownsaved ([:pick \$content (\$pos3+5) \$pos4])\r\
\n :set bytesdowntotal (\$bytesdowncurrent + \$bytesdownsaved)\r\
\n :set megsdowncurrent (\$bytesdowntotal / 1048576)\r\
\n\r\
\n#Begin calculating usage percentage\r\
\n :set percentage ( ( \$bytesdowntotal * 100 ) / ( \$gigs * 1073741824 ) )\r\
\n :log info \"\$sitename: \$percentage%\"\r\
\n:if ([\$email] != \"\" ) do={\r\
\n/tool e-mail send server=\$mailserver from=\$fromaddress to=\$email subject=\"\$sitename: Monthly Report\" body=\"This message is to inform you of the full monthly usage for \$sitename\r\
\n\r\
\nIn this month this site has downloaded \$megsdowncurrent MB, which is \$percentage% of the \$gigs GB monthly download allowance.\r\
\n\r\
\nThis is an Automatically generated E-mail that is sent out at the end of each month.\r\
\n\r\
\nTraffic Monitor System,\r\
\n\$fromaddress\"\r\
\n}\r\
\n#Send email to support/accounts also\r\
\n /tool e-mail send server=\$mailserver from=\$fromaddress to=\$adminaddress subject=\"\$sitename: Monthly Report\" body=\"Full monthly usage for \$sitename\r\
\nIn this month this site has downloaded \$megsdowncurrent MB, which is \$percentage% of the \$gigs GB monthly download allowance.\r\
\n\r\
\nTraffic Monitor System,\r\
\nPlease report any errors in this message to \$fromaddress\"\r\
\n:log info \"Sent monthly report for \$sitename to \$email\"\r\
\n#Set warning level on queue comment back to 00 and reset counters\r\
\n/queue simple set \$i comment=\"\$sitename!\$gigs#\$email!00#0000\"\r\
\n/queue simple reset-counters \$i\r\
\n}\r\
\n}"
add name=manualusagereport policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source=":global mailserver\r\
\n:global adminaddress\r\
\n:global fromaddress\r\
\n:local content\r\
\n:local i\r\
\n:local sitename\r\
\n:local gigs\r\
\n:local email\r\
\n:local megstotal\r\
\n:local totalcurrent\r\
\n:local bytesdowncurrent\r\
\n:local bytesupcurrent\r\
\n:local megsdowncurrent\r\
\n:local megsupcurrent\r\
\n:local percentage\r\
\n:local lastwarning\r\
\n:local warninglevel\r\
\n:local warn\r\
\n:local update\r\
\n:local newwarning\r\
\n:local bytesdownsaved\r\
\n:local bytestotal\r\
\n:local text\r\
\n:local combinedtext\r\
\n:set combinedtext \"\"\r\
\n\r\
\n#Scripts based on Automated billing script at http://wiki.mikrotik.com/wiki/AutomatedBilling\r\
\n# This version created by Andrew Cox - http://www.accessplus.com.au\r\
\n#v1.4 Updated 15th June 2009\r\
\n:log info \"------ Begining Manual Usage Reports -------\"\r\
\n\r\
\n#For each queue in the list\r\
\n:foreach i in=[/queue simple find comment !=\"\"] do={\r\
\n\r\
\n#Pull comment out of queue and divide up accordingly\r\
\n:set content [/queue simple get \$i comment] \r\
\n\r\
\n#Determine variables from comment\r\
\n#Format is: sitename ! gigsallowed # who-to-email ! last warning level(0-50-75-90-99) # data-used (0000)\r\
\n:if ([:find \$content \"!\"] != \"\") do={\r\
\n :local pos1 [:find \$content \"!\"]\r\
\n :local pos4 [:len \$content]\r\
\n :local pos2 ([:find [:pick \$content (\$pos1+1) \$pos4] \"#\"]+\$pos1+1)\r\
\n :local pos3 ([:find [:pick \$content (\$pos2+1) \$pos4] \"!\"]+\$pos2)\r\
\n :set sitename [:pick \$content 0 (\$pos1)]\r\
\n :set gigs [:pick \$content (\$pos1+1) \$pos2]\r\
\n :set email [:pick \$content (\$pos2+1) (\$pos3+1)]\r\
\n :set totalcurrent [/queue simple get \$i bytes]\r\
\n :set lastwarning [:pick \$content (\$pos3+2) (\$pos3+4)]\r\
\n :local pos5 [:find \$totalcurrent \"/\"]\r\
\n :local pos6 [:len \$totalcurrent]\r\
\n :set bytesupcurrent ([:pick \$totalcurrent 0 (\$pos5)])\r\
\n :set bytesdowncurrent ([:pick \$totalcurrent (\$pos5+1) \$pos6])\r\
\n :set megsupcurrent (\$bytesupcurrent / 1048576)\r\
\n :set bytesdownsaved ([:pick \$content (\$pos3+5) \$pos4])\r\
\n :set bytestotal (\$bytesdowncurrent + \$bytesdownsaved)\r\
\n :set megsdowncurrent (\$bytestotal / 1048576)\r\
\n\r\
\n#Begin calculating usage percentage\r\
\n :set percentage ( ( \$bytestotal * 100) / (\$gigs * 1073741824 ) )\r\
\n :log info \"\$sitename: \$percentage% - \$megsdowncurrent MB used - Allowance is \$gigs GB\"\r\
\n :set text \"\$combinedtext \\n \$sitename: \$percentage% - \$megsdowncurrent MB used - Allowance is \$gigs GB\"\r\
\n :set combinedtext \"\$text\"\r\
\n }\r\
\n}\r\
\n:log info \"------ Ending Manual Usage Reports -------\"\r\
\n:local time [/system clock get time]\r\
\n/tool e-mail send server=\$mailserver from=\$fromaddress to=\$adminaddress subject=\"Manual usage report\" body=\"Site Usage report - Runtime: \$time\r\
\n\$text\r\
\n\r\
\nRegards,\r\
\n\$fromaddress\""
add name=gen-usage-queues policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source=\
"#change the target address range to match what you want to generate.\r\
\n:local x\r\
\n:for x from 1 to 254 do={/queue simple add target-address=\"192.168.0.\$x\" queue=\"default/default\"}"
You do not have the required permissions to view the files attached to this post.
 
jandafields
Forum Guru
Forum Guru
Posts: 1515
Joined: Mon Sep 19, 2005 6:12 pm

Re: Testing a script

Thu Dec 22, 2011 11:02 pm

Again, the script on that website is all messed up. That website inserted lots of extra characters. You either have to edit the script and remove the extra \n and extra \r and extra line breaks (they are NOT part of the script!!!)..... or contact the author of the script and ask them to upload it properly.
 
n21roadie
Forum Guru
Forum Guru
Topic Author
Posts: 1949
Joined: Fri Aug 07, 2009 10:36 pm
Location: Limerick,Ireland

Re: Testing a script

Tue Dec 27, 2011 4:06 pm

Asked the author for the script without \n \r - awaiting a reply

Can i also ask back to basic testing of a script is it OK to use terminal and use this method


[admin@Test_Device] /system script :global datum [/system clock get date];
:global time [/system clock get time];
:local percentfree ((100 * [/system resource get free-memory]) / [/system resource get total-memory])

/system resource
:if ($percentfree < 5) do={
/tool e-mail send server=X.X.X.X to="XXXXX@hotmail.com" subject=[/system identity get name] from="alert@yours.net" body=(" on $datum at $time the memory on this repeater got to ", [/system resource get free-memory])
/system reboot;
};

or should it be using for testing (( )) at the start and end of script
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7056
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Testing a script

Tue Dec 27, 2011 4:27 pm

If script contains local variables then put all script inside { }
 
n21roadie
Forum Guru
Forum Guru
Topic Author
Posts: 1949
Joined: Fri Aug 07, 2009 10:36 pm
Location: Limerick,Ireland

Re: Testing a script

Tue Dec 27, 2011 6:32 pm

If script contains local variables then put all script inside { }
Thank you
 
User avatar
THG
Member
Member
Posts: 472
Joined: Thu Oct 15, 2009 1:05 am

Re: Testing a script

Tue Dec 27, 2011 6:40 pm

Again, the script on that website is all messed up. That website inserted lots of extra characters. You either have to edit the script and remove the extra \n and extra \r and extra line breaks (they are NOT part of the script!!!)..... or contact the author of the script and ask them to upload it properly.
This is how the scrips are supposed to look like after the export. You need to save it to a *.rsc file and use the import function.

Example:
/system script
add name=decimal_to_hex policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source="\
    :local dec 3405691582\r\
    \n# set this to number of hex digit you want\r\
    \n:local hexdigit 8\r\
    \n:local nibble\r\
    \n:local hex \"\"\r\
    \n:for i from=1 to=\$hexdigit step=1 do={ \r\
    \n   :set nibble (\$dec&0xf)\r\
    \n   :set hex ([:pick \"0123456789ABCDEF\" \$nibble (\$nibble+1)].\$hex)\r\
    \n   :set dec (\$dec>>4)\r\
    \n}\r\
    \n:log info (\"0x\".\$hex)"
Save the above script to a *.rsc file and upload it to your router.

Issue this command from a terminal.
import filename.rsc
 
n21roadie
Forum Guru
Forum Guru
Topic Author
Posts: 1949
Joined: Fri Aug 07, 2009 10:36 pm
Location: Limerick,Ireland

Re: Testing a script

Tue Dec 27, 2011 9:06 pm

@THG

Thanks your method works OK for the example you posted, tried the script http://www.mikrotik-routeros.com/?p=24
removed the line numbers listed on the webpage but i have syntax errors after second line and import fails, this brings me back to my original question how can a script be tested,

Another question about the following script which reboots a router on high CPU in the example is 95% but how can i set a time delay of say 5mins of high CPU, I don't want the router auto rebooting everytime the CPU load is temporarily high?

{
[admin@Test_Device] /system script :global datum [/system clock get date];
:global time [/system clock get time];
:local percentfree ((100 * [/system resource get free-memory]) / [/system resource get total-memory])

/system resource
:if ($percentfree < 5) do={
/tool e-mail send server=X.X.X.X to="XXXXX@hotmail.com" subject=[/system identity get name] from="alert@yours.net" body=(" on $datum at $time the memory on this repeater got to ", [/system resource get free-memory])
/system reboot;
};
}

Who is online

Users browsing this forum: alixviral, Bing [Bot] and 3 guests