I want to run an update to my address list.
The following code is the idea that tI would like to place in Scheduler to run a script:
import os
file_path = r"/disk2/adiff.txt"
if os.stat(file_path).st_size > 0:
/system script run this_script
else:
do nothing
Anyone know how to code this so that it works under RouterOS?
This seems to work. … no error in terminal … will do some more testing when the value is greater than 0
:if ([:len [/file find name=/disk2/diff.txt]] > 0) do={:system script run job}
Yes, I can confirm that this script works … excellent !!!
Credit goes to @changeip for the idea in the following post
http://forum.mikrotik.com/t/check-if-file-exists/8408/1
Thank you changeip
unfortunately over time the script does NOT perform consistently and I am hopeful that a MT guru can perhaps explain why.
:if ([:len [/file find name=/disk2/diff.txt]] > 0) do={:system script run job5)
Initial tests via terminal indicated that the script worked but after insertion into scheduler the script failed to work – no error is returned nor the desired directive activated.
I have confirmed that my test file has the correct value of either =0 or >0
The following version seems to work far more consistently in terminal— however I need a few days to see if that is remains true.
:if ([:len [/file find name=/disk2/diff.txt]] >= 0) do={:system script run job5}
But I need the script to consistently accept >0 as the correct value if true!
So I am left wondering if the issue has something to do with the USB drive? none of my daily backup and export directives fail to store on that specific drive
… the USB drive I am using in my CCR1009 is the Kingston Digital DataTraveler SE9 16GB USB 2.0
Following is some terminal test that show the inconsistent results – in this case the value of diff is >0
[gate1@citybrook] > :if ([:len [/file find name=/disk2/diff.txt]] != 0) do={:put “system script run job5”}
[gate1@citybrook] > :if ([:len [/file find name=/disk2/diff.txt]] >= 0) do={:put “system script run job5”}
system script run job5
[gate1@citybrook] > :if ([:len [/file find name=/disk2/diff.txt]] > 0) do={:put “system script run job5”}
[gate1@citybrook] > :if ([:len [/file find name=/disk2/diff.txt]] = 0) do={:put “system script run job5”}
system script run job5
[gate1@citybrook] > :if ([:len [/file find name=disk2/diff.txt]] = 0) do={:put “system script run job5”}
[gate1@citybrook] > :if ([:len [/file find name=disk2/diff.txt]] >= 0) do={:put “system script run job5”}
system script run job5
[gate1@citybrook] > :if ([:len [/file find name=disk2/diff.txt]] > 0) do={:put “system script run job5”}
system script run job5
[gate1@citybrook] > :if ([:len [/file find name=disk2/diff.txt]] != 0) do={:put “system script run job5”}
system script run job5
[gate1@citybrook] > :if ([:len [/file find name=disk2/diff.txt]] = 0) do={:put “system script run job5”}
[gate1@citybrook] > :if ([:len [/file find name=disk2/diff.txt]] > 0) do={:put “system script run job5”}
system script run job5
[gate1@citybrook] >
When I change /disk2/diff.txt to disk2/diff.txt — removing the first / ----- I do get better results but this is a very short period … will need to do more testing over time.
Ok I have identified the CULPRIT … ITS the prefix / … leaving that off seems to provide far better consistency
So name=disk2/ is the way to go … is that documented somewhere ???