m9679
April 23, 2014, 2:14am
1
Hi. Sure would appreciate some guidance with the following problem. So far, not much useful information to go on.
Summary:
Router OS v6.11 on CCR1016-12G (no updates available from /system package update check-for-updates)
A script fails to create an export file when run from a schedule
Script works fine when run manually
Script is owned by admin user
Schedule item is owned by admin user
Admin user is a member of the “full” group
No errors are produced in the logs or console at the time of the error
Script uses :do {} on-error{} around the /export command so no error code is produced
We are not aware of a way to see the error code inside a script executed from a schedule item (so we can’t see what error is occurring)
The error happens whether or not we include the hide-sensitive flag
The scheduled script fails at all times of day
The script runs successfully manually at all times of day
Further details:
/system script print detail
Flags: I - invalid
0 name="Config_Email" owner="admin" policy=reboot,read,write,policy,test,password,sniff,sensitive last-started=apr/23/2014 13:58:10 run-count=60 source=
{
:log info "CONFIG EXPORT - Script beginning";
:local systemname [/system identity get name];
:local systemdate [/system clock get date];
:local filename ($systemname . "-" . [:pick $systemdate 7 11] . [:pick $systemdate 0 3] . [:pick $systemdate 4 6]);
:local filenamersc ($filename . ".rsc");
:local toaddress "name@domain.tld ";
:local subj ($systemname . " Backup " . $systemdate);
:do { /file rem [/file find name=$filenamersc]; }
on-error={ :log info ("CONFIG EXPORT - Existing file did NOT exist - AOK then...") };
:log info ("CONFIG EXPORT - About to export to " . $filenamersc);
THIS NEXT LINE CREATES AN ERROR ONLY WHEN RUN FROM SCHEDULE ITEM
:do { /export hide-sensitive file=$filename;}
on-error={ :log info ("CONFIG EXPORT - FAILED to create file " . $filenamersc) };
:log info ("CONFIG EXPORT - About to email " . $filenamersc . " to " . $toaddress);
:do { /tool e-mail send to=$toaddress subject=$subj file=$filenamersc start-tls=yes;}
on-error={ :log info ("CONFIG EXPORT - System Backup file " . $filenamersc . " FAILED to send to " . $recipient);};
:delay 10;
#/file rem [/file find name=$filenamersc];
:log info "CONFIG EXPORT - Script completed";
}
/system sched print detail
Flags: X - disabled
0 name="Sched_Config_Email" start-time=startup interval=5m on-event=Config_Email owner="admin" policy=reboot,read,write,policy,test,password,sniff,sensitive run-count=29
next-run=13:58:09
Next time, when post on forum, use /export compact, or in this case /system script export compact, not the print function for clarity.
Now I check the script, wait 10 minutes for answer.
I change the interval from 5 minutes to 1 day, is more logical…
Also is not good to start this script at startup…
I fix also some errors on the script, if you like you want add again “:info” step by step, but is not really needed.
Before ask why is not present “hide-sensitive” on the script, read again: miss “sensitive” right to the script…
I also fix some errors on email: “from” and “body” are not presents…
You have put System Identity Name on file name, remember to use only A-Z, a-z, 0-9, “-”, " " and “_” on name, or you can produce invalid filename.
/system scheduler
add name=Job-Send-Export-Email policy=read interval=1d start-date=jan/02/1970 start-time=00:01:00 on-event="/system script run Send-Export-to-Email;";
/system script
add name=Send-Export-to-Email policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,api source=":log info message=\"Start execution of Send-Export-to-Email\";\r\n\
:local sysName value=[/system identity get name];\r\n\
:local sysDate value=[/system clock get date];\r\n\
:local sysTime value=[/system clock get time];\r\n\
:local fileName value=(\$sysName.\"-\".[:pick \$sysDate 7 11].[:pick \$sysDate 0 3].[:pick \$sysDate 4 6]);\r\n\
:local fileNameRsc value=(\$fileName.\".rsc\");\r\n\
:local toAddress value=\"name@domain.tld\";\r\n\
:local mailSubject value=(\$sysName.\" backup \".\$sysDate.\" \".\$sysTime);\r\n\
/export compact file=\$fileName;\r\n\
/tool e-mail send from=\"script@routerboard.local\" to=\$toAddress subject=\$mailSubject file=\$fileNameRsc body=(\$mailSubject.\" \".\$fileNameRsc) start-tls=yes;\r\n\
:delay delay-time=10s;\r\n\
/file remove \$fileName;\r\n\
:log info message=\"Send-Export-to-Email correctly executed\";"
If I have helped you, please add Karma.
m9679
April 23, 2014, 9:20pm
4
I appreciate you taking the time, thanks, but I wasn’t asking for help with the script. I was asking:
Why the export command fails on schedule but not when running the script manually
How to find out why it is failing (since the on-error doesn’t appear to allow access to error codes, and nothing is written to the logs/console even after I echo all error topics)
The rest of the script works just fine in the context of the rest of the system (/tool e-mail config etc).
m9679:
I appreciate you taking the time, thanks, but I wasn’t asking for help with the script. I was asking:
Why the export command fails on schedule but not when running the script manually
How to find out why it is failing (since the on-error doesn’t appear to allow access to error codes, and nothing is written to the logs/console even after I echo all error topics)
The rest of the script works just fine in the context of the rest of the system (/tool e-mail config etc).
Read carefully what other users write to you,
if I have spent my time fixing the script, READ first the script and try to understand why is different…
Before ask why is not present “hide-sensitive” on the script, read again: miss “sensitive” right to the script…
Some bigger error on script:
/system script print detail
Flags: I - invalid
0 name=“Config_Email” owner=“admin” policy=reboot,read,write,policy,test,password,sniff,> sensitive > last-started=apr/23/2014 13:58:10 run-count=60 source=
{
:log info “CONFIG EXPORT - Script beginning”;
:local systemname [/system identity get name];
:local systemdate [/system clock get date];
:local filename ($systemname . “-” . [:pick $systemdate 7 11] . [:pick $systemdate 0 3] . [:pick $systemdate 4 6]);
:local filenamersc ($filename . “.rsc”);
:local toaddress "> name@domain.tld > ";
:local subj ($systemname . " Backup " . $systemdate);
:do { /file rem [/file find name=$filenamersc]; }
on-error={ :log info (“CONFIG EXPORT - Existing file did NOT exist - AOK then…”) };
:log info ("CONFIG EXPORT - About to export to " . $filenamersc);
THIS NEXT LINE CREATES AN ERROR ONLY WHEN RUN FROM SCHEDULE ITEM
:do { /export > hide-sensitive > file=$filename;}
on-error={ :log info ("CONFIG EXPORT - FAILED to create file " . $filenamersc) };
:log info ("CONFIG EXPORT - About to email " . $filenamersc . " to " . $toaddress);
:do { /tool e-mail send to=$toaddress subject=$subj file=$filenamersc start-tls=yes > > ;}
on-error={ :log info ("CONFIG EXPORT - System Backup file " . $filenamersc . " FAILED to send to " . $recipient);};
:delay 10;
#/file rem [/file find name=$filenamersc];
:log info “CONFIG EXPORT - Script completed”;
}
/system sched print detail
Flags: X - disabled
0 name=“Sched_Config_Email” start-time=> startup > interval=5m on-event=> “/system script run > Config_Email> ;” > owner=“admin” policy=reboot,read,write,policy,test,password,sniff,sensitive run-count=29
next-run=13:58:09
tawh
April 25, 2014, 4:06am
6
I also encounter the same problem on scripting of /export command
Just put it simple, I created a script through webGUI called “test” with only the following line.
/export file=test
when I click “Run Script” with the webGUI, script executed but nothing happened.
when I ssh to the router and run
/system script run "test"
the test.rsc produced.
I suspect there is problem on executing export command through non-interactive shell.
tawh:
I also encounter the same problem on scripting of /export command
Just put it simple, I created a script through webGUI called “test” with only the following line.
/export file=test
when I click “Run Script” with the webGUI, script executed but nothing happened.
when I ssh to the router and run
/system script run "test"
the test.rsc produced.
I suspect there is problem on executing export command through non-interactive shell.
RouterOS version?
if you not use $variable, you must put the quotes and “;” at the end…
/export file=“test”;
tawh
April 25, 2014, 5:23pm
8
rextended:
mine is V6.12
no different with your suggested change, I don’t think this is related to the syntax.
Could you please state the version which works with it?
tawh:
rextended:
mine is V6.12
no different with your suggested change, I don’t think this is related to the syntax.
Could you please state the version which works with it?
6.13rc6
We discovered a bug: webfig when create a script forget to set “ftp” right to the script.
If the script are created by cli or by winbox, the script is working.
See here for more details:
http://forum.mikrotik.com/viewtopic.php?f=1&t=84044&p=423085#p423085
tawh
April 25, 2014, 8:11pm
10
To feed more information for this problem, if the script changes to
"/system backup save name=test"
, the default policy setting doesn’t cause any problem, thus I suspect the “/export” command is an exception rather than the default policy setting.
Just my 2 cents.