Page 1 of 1
scheduler and script creating file..
Posted: Wed Mar 10, 2010 9:09 am
by Multik
Good day!
I'm trying to create script for ping some hosts every 5 min, and results must send to email only one time (reachable/unreachable). Script create file-flag for checking mail was sended or not. From 'script' repository all working fine. But if i save his in Scheduler - create file not working
![Sad :(](./images/smilies/icon_sad.gif)
i'm tryed to enable all policy.
Mikrotik 1000 - RouterOS 4.6
Re: scheduler and script creating file..
Posted: Wed Mar 10, 2010 9:36 am
by mrz
let us see your whole script.
Re: scheduler and script creating file..
Posted: Wed Mar 10, 2010 1:09 pm
by Multik
i'm resolve problem..
i'm try to post text of script to scheduler, instead of call script from scheduler
![Smile :)](./images/smilies/icon_smile.gif)
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 12:58 pm
by zervan
I've found this topic, but not the answer. A need to create file from scheduler, but it is not working. Here is simple schedule "On Event":
But file is not created from scheduler. If I create a script, it is working when I start it in normal way but not from scheduler.
A have 750G RouterOS v. 4.13
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 1:45 pm
by SurferTim
"print" does not work with the scheduler, only the command line. ":put" is the same.
Create the file with the command line, then set the contents with the scheduler.
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 2:17 pm
by zervan
"print" does not work with the scheduler, only the command line.
There is no way to do that?
Create the file with the command line, then set the contents with the scheduler.
It isn't solution for me, because I need to create new file every time - it will save traffic statistics for every user (simple queue), here is my script:
:local date [/system clock get date]
:local time [/system clock get time]
:local file ("stat-".[:pick $date 7 11]."-".[:pick $date 0 3]."-".[:pick $date 4 6]."-".[:pick $time 0 2].[:pick $time 3 5])
/file print file=$file
:delay 1
/queue simple
:local stat
:for i from=0 to=12 do={:set stat ($stat.[get $i name].":".[get $i bytes]."\n")}
/file set $file contents=$stat
It works fine, but when scheduled, no file is created.
Perhaps i could modify my script to open webserver's URL with this data in GET parameter - webserver will save them to file.
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 2:35 pm
by SurferTim
There is almost always a way to cheat.
/ip address export file=test
The file will be test.rsc.
Then modify the contents on it.
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 3:23 pm
by SurferTim
BTW, "print file=test" works with V4.11. Just "print" still does not work.
/file print file=test
creates file test.txt
You must declare the variable $file to use your script.
:global file;
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 3:49 pm
by zervan
/ip address export file=test
The file will be test.rsc.
Not working in scheduler (works only in script without scheduler), I've also tried "/system identity export file=test". I've tried this on RB750 v. 4.13 as well - not working. Is it working for you in scheduler? Maybe for 4.11 it is fine and in 4.13 not?
You must declare the variable $file to use your script.
:global file;
It is declared (:local file) - script is working (without scheduler) and is not point of problem, only illustration. Let's try to solve this as simple command in scheduler - the goal is creation of file.
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 3:52 pm
by SurferTim
I tried it on V4.11. This works with the scheduler:
:local myfile "test";
/file print file=$myfile;
creates file test.txt
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 4:00 pm
by zervan
I tried it on V4.11. This works with the scheduler:
:local myfile "test";
/file print file=$myfile;
creates file test.txt
Thanks for test!
Not working on 4.13 - so here is the problem
Is it a bug or something was changed and is here some other (new) way to create file?
Or is something wrong on my side, what I didn't notice?
I've selected everything on Policy settings of schedule (just for sure).
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 4:06 pm
by SurferTim
Are you certain it is not creating the file?
/file print detail where name=test.txt
should show the file. Maybe not the contents. Mine is larger than 4095 characters.
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 4:11 pm
by zervan
Are you certain it is not creating the file?
/file print detail where name=test.txt
should show the file. Maybe not the contents. Mine is larger than 4095 characters.
Yes, I'm sure - I'm checking it using scp. But I've also tried your command - just for sure.
If I run any of file-creating commands without scheduler (in telnet or in normal script and manual Run), it is working. But something is wrong with scheduler, maybe bug in scheduler's permissions/policy?
Is somebody with 4.13 here to check this? I've tried it on two mikrotiks (750 and 750G), but maybe I've something wrong on both of them.
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 4:21 pm
by SurferTim
Upgraded my Rb433ah to V4.13. The script still works fine!
Are you certain the scheduler has run? "/system scheduler print" and insure the "run count" has incremented.
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 4:36 pm
by zervan
Upgraded my Rb433ah to V4.13. The script still works fine!
Are you certain the scheduler has run? "/system scheduler print" and insure the "run count" has incremented.
Thanks for another test! Yes, script is running every 15 seconds - I forgot to stop it, so it has run count on 230 now
I don't know what could be possibly wrong. But I've notice one more thing: on 4.11 was working this without any problems:
/file print file=$file
/file set $file contents=$stat
But on 4.13 it is not - second command is not executed. But if I add ":delay 1" between them, it is working on 4.13 as well (without scheduler).
Is it possible that there may be some bug in 4.13 on R750(G) and not on RB433AH? I don't think so - so there must be some other reason, hardly to find for me
If I would give you access to my mikrotik (secondary, backup), could you look around there?
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 4:47 pm
by SurferTim
Try this:
:local myfile "test";
:local file ($myfile . ".txt");
/file print file=$myfile
/file set $file contents="new contents";
When you create the file, the filename is not "test", it is "test.txt"
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 5:04 pm
by zervan
Try this:
:local myfile "test";
:local file ($myfile . ".txt");
/file print file=$myfile
/file set $file contents="new contents";
When you create the file, the filename is not "test", it is "test.txt"
You are right that I should add extension on setting contents.
This (above) script is working on my RB750, but not working on RB750G - the file test.txt contains listing of files. Of course, second run without deleting the file will succeed.
If I add ":delay 1" between them, it will work on 750G as well.
None of them is working in scheduler.
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 5:08 pm
by SurferTim
Then I would wait for the scheduler to run, then create a supout.rif file and email it to support (at) mikrotik.com with an explanation of the problem, and mention it is the RB750 series.
/system sup-output
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 7:38 pm
by dssmiktik
I tested this on v4.13 x86, and it worked, test.txt file created successfully.
{
/system scheduler
add comment="" disabled=no interval=15s name=schedule1 on-event=script1 \
policy=reboot,read,write,policy,test,password,sniff,sensitive start-time=\
startup
/system script
add name=script1 policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source=\
":local myfile \"test\";\r\
\n/file print file=\$myfile;\r\
\n"
}
Try to copy/paste these commands in terminal and see it it works (it should create a script and scheduler for you).
Re: scheduler and script creating file..
Posted: Sun Nov 07, 2010 9:38 pm
by zervan
{
/system scheduler
add comment="" disabled=no interval=15s name=schedule1 on-event=script1 \
...
Thanks a lot! It is working!
The difference is that you have only "script1" and I had written "/system script run script1", which was not working correctly. It is strange, indeed, but working. I don't know why I had written that longer command - probably I've seen that on other scripts?