sending mail when I get a new file-possible?

hello ,
I have connected a device that send me log.txt file to the RB using FTP.
how can I write a script that whenever the file is copied he will send it to me to mail?
how do I make the script “choose” the latest file that was created?
and them continue to other file ,and so on and on…

I have try to get the file name by using this command :

 :put [/file get  [find where creation-time=dec/18/2013 15:45:48] name ]

but I get no such file… (although I have this file )

What am I missing?

Thank ,

Does the file name stay the same (and a new one overwrites the old one)? Or are you trying to check all files and email yourself only the latest one?

If there are spaces in a string, make sure to quote them:
:put [/file get [find where creation-time=“dec/18/2013 15:45:48”] name ]

the file name is changing according to the time it’s been created
for ex -
FTP_2013-12-18-_14-41-55_142.log
FTP_2013-12-18-_14-42-02_632.log

if I have 10 files with different creation-time , how do I make him send me every time the oldest he didn’t send ?
let me give an example -
I have 10 file with different name\creation-time .
I need to know when it was the last time he send a file - the it will save it in variable “old_time”
and then it will run all the files until he find a file with newer creation-time ,send it -and change “old_time”

the script will run every 1 min , one time.

hope it’s clear

Thanks for the help ,

what you said about the quote did help - so manually I can see what is the last one and send it

:global new [/file get [find where creation-time="dec/18/2013 17:39:45"] name];
:log warning "New file";
tool e-mail send to="MyEmail@gmail.com" subject="LOG file " tls=yes from=Unit1" body="lof file" file=$new;
:log warning "E-mail send";
:log warning "************";

this is what I have done so far
I decided to run by number of file and always see what is file number 0 and compare it to a file with the last name
call LastFile.txt

:global new [/file get number=0 name] ;
:global old [/file get Last/LastFile.txt content];
if ($old=$new ) do={:log warning message="No need to send" ;set old ($new ); file set [file find name=Last/LastFile.
txt] contents=$new ;/file remove [find name=$new]} else={:log warning message="NEED To SEND MAIL!!!!!!";/system script run mail; file set [find name=Last/LastFile.txt] contents=$new ; /file remove [find name=$new]}

but it not always working for me
I have have 10 files and I get always “no need to send” , why is it ?

also when I run the command manually one by one it’s working …


Thanks ,

This is how I would do it. This script stores the “date/time stamp” into the schedule’s comment field (to survive reboots, which a global variable won’t do). It gets the date and time values from the comment and then checks all “FTP…log” files for any that are newer, and sends email if any are found. Make sure to change the first line to be the schedule you want to store the variable in. I adapted this from another script found here: http://forum.mikrotik.com/t/compare-dates/53609/1
:local scheduleName “checkFTPlogs”

:local months {“jan”;“feb”;“mar”;“apr”;“may”;“jun”;“jul”;“aug”;“sep”;“oct”;“nov”;“dec”}
:local toggle false
/file

:foreach i in=[find name~“^FTP.+log”] do={

:local current [/system scheduler get [find name=“$scheduleName”] comment]
:local cyr [:pick $current 7 11]
:local cmo [:find $months [:pick $current 0 3]]
:if ($cmo < 10) do={ :set cmo (“0” . $cmo); }
:local cday [:pick $current 4 6]
:local chr [:pick $current 12 14]
:local cmin [:pick $current 15 17]
:local csec [:pick $current 18 20]
:local currentDate ($cyr.$cmo.$cday.$chr.$cmin.$csec)

:local new [get $i creation-time]
:local nyr [:pick $new 7 11]
:local nmo [:find $months [:pick $new 0 3]]
:if ($nmo < 10) do={ :set nmo (“0” . $nmo); }
:local nday [:pick $new 4 6]
:local nhr [:pick $new 12 14]
:local nmin [:pick $new 15 17]
:local nsec [:pick $new 18 20]
:local newDate ($nyr.$nmo.$nday.$nhr.$nmin.$nsec)

:if ($newDate > $currentDate) do={
:set toggle true
/system scheduler set [find name=“$scheduleName”] comment=“$new”
}
}

:if ($toggle = true) do={
:log warning message=“NEED To SEND MAIL!!!”
/system script run mail
}