Community discussions

MikroTik App
 
mattsawatzky
newbie
Topic Author
Posts: 41
Joined: Wed Oct 27, 2010 12:43 am

Export to File - Filename Variable

Tue Nov 26, 2013 11:51 pm

I'm trying to create a script to create a n export of the config and save it with a filename with the date and time in it. I can't get it to work if the filename has the variable $filename in it. If I make it say file=test235 it creates the file with the name test235 just fine. Any suggestions? I've tried the variable in "" and in [] as well.
:local hostname "walker";
:local time [/system clock get time];
:local date [/system clock get date];
:local filename "$hostname-$time-$date";

export compact file=$filename

:log info "Current Time:$time"
 
User avatar
skot
Long time Member
Long time Member
Posts: 586
Joined: Wed Nov 30, 2011 3:05 am

Re: Export to File - Filename Variable

Wed Nov 27, 2013 6:17 am

The date contains forward slashes which can't be used in file names. You could use [:pick] and extract the date out, something like:
:local date ([:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . [:pick [/system clock get date] 7 11]);
I don't need any karma... I have Ιησους Χριστος!
 
mattsawatzky
newbie
Topic Author
Posts: 41
Joined: Wed Oct 27, 2010 12:43 am

Re: Export to File - Filename Variable

Wed Nov 27, 2013 10:40 pm

You're the man. Thank you :).
 
ndbjorne
just joined
Posts: 22
Joined: Sat Dec 15, 2012 5:06 pm
Location: Italy

Re: Export to File - Filename Variable

Wed Nov 27, 2013 10:42 pm

This is mine
I only tested id in ROS6.6 but it should work on most versions.
File name is formatted according to
/system backup save
to sort them.
{
:local curDate [/system clock get date]
:local curTime [/system clock get time]
:local systemName [/system identity get name]
:local curMonth [:pick $curDate 0 3]
 :set curMonth ( [ :find key="$curMonth" in="jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec" from=-1 ] / 4 + 1)
 if ( $curMonth < 10 ) do={
  :set curMonth ( "0".$curMonth )
 } else={
  :set curMonth $curMonth
 }
:local curDay   [:pick $curDate 4 6]
:local curYear  [:pick $curDate 7 13]
:local curHour  [:pick $curTime 0 2]
:local curMin   [:pick $curTime 3 5]

/
/export compact file=( "$systemName"."-"."$curYear"."$curMonth"."$curDay" ."-"."$curHour"."$curMin" )
}
Bye
Andrea
 
ghoroubi
just joined
Posts: 1
Joined: Tue Dec 06, 2016 11:17 am

Re: Export to File - Filename Variable

Tue Dec 06, 2016 11:32 am

I want to create file name if a format with some letter and some numbers,like ABC001,ABC002,...
I need scripts that can change file name everyone runs to avoid replace and delete previous one.
thanks

Who is online

Users browsing this forum: No registered users and 35 guests