Community discussions

MikroTik App
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Why the file is not created

Sun Sep 18, 2022 10:13 pm

I am using these scripts made by REXTENDED, I have copied and pasted the same as the original scripts and I cannot find why the file is not created
:global addLogToFile do={
    :local filename "$1"
    :local fileext  ".txt" 
    :local maxlen 4095
    /file
    :if ([:len [find where name="flash" and type="disk"]] = 1) do={:set filename "flash/$filename"}
    :local wkfilename "$filename$fileext"
    :if ([:len [find where name=$wkfilename]] = 0) do={print file="$wkfilename"; :delay 5s; set $wkfilename contents=""}
    :local filecon [get $wkfilename contents]
    :local filelen [:len $filecon]
    :local addthis "$2\r\n"
    :local addlen  [:len $addthis]
    :if (($filelen + $addlen) > $maxlen) do={
        :set filecon ""
        :set filelen 0
        :delay 1s
    }
    :set filecon  "$filecon$addthis"
    set $wkfilename contents=$filecon
    :delay 1s
}

/system
:local date [clock get date]
:set $date ([:pick "$date" 4 7]."".[:pick "$date" 0 4]."".[:pick "$date" 7 11])
:local time [clock get time]
:set $time ([:pick "$time" 0 2]."".[:pick "$time" 2 8])

/file
:local filename "TESTING"
:local filecontent [get $filename contents]
:local newfilecontent  "*********************************************\r\nTIME:  $time          DATE:   $date\r\n$filecontent"
[$addLogToFile $filename $newfilecontent]
set $filename contents=$newfilecontent

taking advantage of the help, how would I send the file by mail before it is deleted?
Thanks for the help.



EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Why the file is not created

Mon Sep 19, 2022 10:56 am

You altered my function.
If there were things written inside it was not by random.
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Why the file is not created

Mon Sep 19, 2022 4:02 pm

I can't find where I'm wrong REX, help me please,





EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Why the file is not created  [SOLVED]

Mon Sep 19, 2022 4:49 pm

Try to stop to copy & paste random script here and there.
:global addLogToFile do={
    :local filename "$1"
    :local fileext  ".txt" ; # can be only .txt !!!
    :local maxlen 4095
    /file
    :if ([:len [find where name="flash" and type="disk"]] = 1) do={:set filename "flash/$filename"}
    :local wkfilename "$filename$fileext"
    :if ([:len [find where name=$wkfilename]] = 0) do={print file="$wkfilename"; :delay 2s; set $wkfilename contents=""; :delay 1s}
    :local filecon [get $wkfilename contents]
    :local filelen [:len $filecon]
    :local addthis "$2\r\n"
    :local addlen  [:len $addthis]
    :if (($filelen + $addlen) > $maxlen) do={
        :set filecon ""
        :set filelen 0
        :delay 2s
    }
    :set filecon  "$filecon$addthis"
    set $wkfilename contents=$filecon
    :delay 1s
}

{
/system clock
:local date [get date]
:local time [get time]
:set $date "$[:pick $date 4 7]$[:pick $date 0 4]$[:pick $date 7 11]"

:local filename "TESTING" ; # do not put any extension, only the filename
:local logthis  "*********************************************\r\nTIME:  $time          DATE:   $date"
[$addLogToFile $filename $logthis]
}
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Why the file is not created

Mon Sep 19, 2022 5:13 pm

Thanks REX, in the file write like this.
script1.jpg


But I would like you to write like this, of course if you can.
scrirt2.jpg


EL DONCITO.
You do not have the required permissions to view the files attached to this post.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Why the file is not created

Mon Sep 19, 2022 5:25 pm

What is? The game "Find the differences between two images"?
How many are they?
Maybe a description...


simplye change
:set filecon  "$filecon$addthis"

with
:set filecon  "$addthis$filecon"
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Why the file is not created

Mon Sep 19, 2022 5:48 pm

Excuse me friend REX, I did it as you recommended and it's still the same.



EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Why the file is not created

Mon Sep 19, 2022 5:50 pm

Is not possible, you done it wrong.
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Why the file is not created

Mon Sep 19, 2022 5:53 pm

:global addLogToFile do={
    :local filename "$1"
    :local fileext  ".txt" ; # can be only .txt !!!
    :local maxlen 4095
    /file
    :if ([:len [find where name="flash" and type="disk"]] = 1) do={:set filename "flash/$filename"}
    :local wkfilename "$filename$fileext"
    :if ([:len [find where name=$wkfilename]] = 0) do={print file="$wkfilename"; :delay 2s; set $wkfilename contents=""; :delay 1s}
    :local filecon [get $wkfilename contents]
    :local filelen [:len $filecon]
    :local addthis "$2\r\n"
    :local addlen  [:len $addthis]
    :if (($filelen + $addlen) > $maxlen) do={
        :set filecon ""
        :set filelen 0
        :delay 2s
    }
    :set filecon  "$addthis$filecon"
    set $wkfilename contents=$filecon
    :delay 1s
}

{
/system clock
:local date [get date]
:local time [get time]
:set $date "$[:pick $date 4 7]$[:pick $date 0 4]$[:pick $date 7 11]"

:local filename "TESTING" ; # do not put any extension, only the filename
:local logthis  "*********************************************\r\nTIME:  $time          DATE:   $date"
[$addLogToFile $filename $logthis]
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Why the file is not created

Mon Sep 19, 2022 5:59 pm

Check yourself what you done wrong,
for me work:

TESTING code

*********************************************
TIME:  01:00:10          DATE:   02/jan/1970
*********************************************
TIME:  00:59:57          DATE:   02/jan/1970
*********************************************
TIME:  00:59:44          DATE:   02/jan/1970
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Why the file is not created

Mon Sep 19, 2022 10:07 pm

The script is working very well friend Rex, how can I send the file before it reaches 4095 bits by mail





EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Why the file is not created

Mon Sep 19, 2022 10:44 pm

I'm not going to edit the script one bit at a time again,
because every time you add a subsequent request instead of clearly explaining what you need.
Check how long it takes to fill up, and have it sent out on a regular basis before it fills up.

Who is online

Users browsing this forum: ko00000000001, zandhaas and 20 guests