Community discussions

MikroTik App
 
Multik
newbie
Topic Author
Posts: 29
Joined: Wed Mar 10, 2010 9:00 am

scheduler and script creating file..

Wed Mar 10, 2010 9:09 am

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 :( i'm tryed to enable all policy.

Mikrotik 1000 - RouterOS 4.6
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7198
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: scheduler and script creating file..

Wed Mar 10, 2010 9:36 am

let us see your whole script.
 
Multik
newbie
Topic Author
Posts: 29
Joined: Wed Mar 10, 2010 9:00 am

Re: scheduler and script creating file..

Wed Mar 10, 2010 1:09 pm

i'm resolve problem..

i'm try to post text of script to scheduler, instead of call script from scheduler :)
 
User avatar
zervan
Member
Member
Posts: 329
Joined: Fri Aug 20, 2010 10:43 pm
Location: Slovakia
Contact:

Re: scheduler and script creating file..

Sun Nov 07, 2010 12:58 pm

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":
/file print file=test
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
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: scheduler and script creating file..

Sun Nov 07, 2010 1:45 pm

"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.
 
User avatar
zervan
Member
Member
Posts: 329
Joined: Fri Aug 20, 2010 10:43 pm
Location: Slovakia
Contact:

Re: scheduler and script creating file..

Sun Nov 07, 2010 2:17 pm

"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.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: scheduler and script creating file..

Sun Nov 07, 2010 2:35 pm

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.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: scheduler and script creating file..

Sun Nov 07, 2010 3:23 pm

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;
 
User avatar
zervan
Member
Member
Posts: 329
Joined: Fri Aug 20, 2010 10:43 pm
Location: Slovakia
Contact:

Re: scheduler and script creating file..

Sun Nov 07, 2010 3:49 pm

/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.
You do not have the required permissions to view the files attached to this post.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: scheduler and script creating file..

Sun Nov 07, 2010 3:52 pm

I tried it on V4.11. This works with the scheduler:
:local myfile "test";
/file print file=$myfile;
creates file test.txt
 
User avatar
zervan
Member
Member
Posts: 329
Joined: Fri Aug 20, 2010 10:43 pm
Location: Slovakia
Contact:

Re: scheduler and script creating file..

Sun Nov 07, 2010 4:00 pm

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).
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: scheduler and script creating file..

Sun Nov 07, 2010 4:06 pm

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.
 
User avatar
zervan
Member
Member
Posts: 329
Joined: Fri Aug 20, 2010 10:43 pm
Location: Slovakia
Contact:

Re: scheduler and script creating file..

Sun Nov 07, 2010 4:11 pm

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.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: scheduler and script creating file..

Sun Nov 07, 2010 4:21 pm

Upgraded my Rb433ah to V4.13. The script still works fine! :D

Are you certain the scheduler has run? "/system scheduler print" and insure the "run count" has incremented.
 
User avatar
zervan
Member
Member
Posts: 329
Joined: Fri Aug 20, 2010 10:43 pm
Location: Slovakia
Contact:

Re: scheduler and script creating file..

Sun Nov 07, 2010 4:36 pm

Upgraded my Rb433ah to V4.13. The script still works fine! :D

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?
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: scheduler and script creating file..

Sun Nov 07, 2010 4:47 pm

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"
 
User avatar
zervan
Member
Member
Posts: 329
Joined: Fri Aug 20, 2010 10:43 pm
Location: Slovakia
Contact:

Re: scheduler and script creating file..

Sun Nov 07, 2010 5:04 pm

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.
Last edited by zervan on Sun Nov 07, 2010 5:09 pm, edited 1 time in total.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: scheduler and script creating file..

Sun Nov 07, 2010 5:08 pm

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
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: scheduler and script creating file..

Sun Nov 07, 2010 7:38 pm

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).
 
User avatar
zervan
Member
Member
Posts: 329
Joined: Fri Aug 20, 2010 10:43 pm
Location: Slovakia
Contact:

Re: scheduler and script creating file..

Sun Nov 07, 2010 9:38 pm

{
/system scheduler
add comment="" disabled=no interval=15s name=schedule1 on-event=script1 \
...
Thanks a lot! It is working! :-D

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?