Community discussions

MikroTik App
 
bourneagainsh
newbie
Topic Author
Posts: 35
Joined: Thu May 21, 2020 7:41 pm

"\$(HOSTNAME)_\$(FIRMWARE)_\$(DATE)-\$(TIME)"

Sun Feb 07, 2021 12:28 am

I would like to name automatically my export file in the following format:
hEX_S-RB760iGS_6.48.1_20210206-193801

where:
hEX_S-RB760iGS - Hostname
_6.48.1 - Current Firmware
_20210206 - Current Date YYYYMMDD
-193801 - Current time HHMMSS

I have tried the following, but no luck:
export file="\$(HOSTNAME)_\$(FIRMWARE)_\$(DATE)-\$(TIME)"

Does anyone know how to achieve this for "export file" command?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 6195
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: "\$(HOSTNAME)_\$(FIRMWARE)_\$(DATE)-\$(TIME)"

Mon Feb 08, 2021 10:08 am

file="$HOSTNAME_$FIRMWARE_$DATE-$TIME"

keeping in mind that all of those variables are actually defined.
 
bourneagainsh
newbie
Topic Author
Posts: 35
Joined: Thu May 21, 2020 7:41 pm

Re: "\$(HOSTNAME)_\$(FIRMWARE)_\$(DATE)-\$(TIME)"

Mon Feb 08, 2021 1:06 pm

Great, where do I need them to be defined? ;)

I have set Hostname, system knows the current firmware and date/time on Mikrotik.

On my PC's running Debian, when I backup my Firefox browser settings I execute:
tar -cvf BackUp_Firefox_$(hostname)_$(date +%Y%m%d-%H%M%S).tar -P ~/.mozilla/firefox/
so I guess, same approach does not work on MikroTik ....

Executing the:
/export file="$HOSTNAME_$FIRMWARE_$DATE-$TIME"
would result in file:
13 __-.rsc script 23.9KiB feb/08/2021 11:00:55
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 6195
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: "\$(HOSTNAME)_\$(FIRMWARE)_\$(DATE)-\$(TIME)"

Mon Feb 08, 2021 2:31 pm

 
nostromog
Member Candidate
Member Candidate
Posts: 207
Joined: Wed Jul 18, 2018 3:39 pm

Re: "\$(HOSTNAME)_\$(FIRMWARE)_\$(DATE)-\$(TIME)"

Mon Feb 08, 2021 3:17 pm

I would like to name automatically my export file in the following format:
hEX_S-RB760iGS_6.48.1_20210206-193801

where:
hEX_S-RB760iGS - Hostname
_6.48.1 - Current Firmware
_20210206 - Current Date YYYYMMDD
-193801 - Current time HHMMSS

I have tried the following, but no luck:
export file="\$(HOSTNAME)_\$(FIRMWARE)_\$(DATE)-\$(TIME)"

Does anyone know how to achieve this for "export file" command?
You could do something like
[admin@Mikrotik] > {/system; :put "$[identity get name]_$[routerboard get current-firmware ]_$[clock get date]-$[clock get time]"; / }        
Mikrotik_7.1beta4_feb/08/2021-14:06:13
Or use
/system resource get version
instead of the installed firmware. You might also prefer
/system routerboard get serial-number 
.

I used a curly brackets block to allow to "chdir" to /system, and save some typing, and then at the end "chdir" back to "/". If you know bash, you'll see that routeros uses
$(varname)
where bash uses
${varname}
, and
$[command]
where bash uses
$(command)
 
teknologs
just joined
Posts: 3
Joined: Mon Oct 31, 2016 10:30 pm

Re: "\$(HOSTNAME)_\$(FIRMWARE)_\$(DATE)-\$(TIME)"

Mon Feb 08, 2021 6:36 pm

I would like to name automatically my export file in the following format:
hEX_S-RB760iGS_6.48.1_20210206-193801

where:
hEX_S-RB760iGS - Hostname
_6.48.1 - Current Firmware
_20210206 - Current Date YYYYMMDD
-193801 - Current time HHMMSS

I have tried the following, but no luck:
export file="\$(HOSTNAME)_\$(FIRMWARE)_\$(DATE)-\$(TIME)"

Does anyone know how to achieve this for "export file" command?
:local version [/system package update get installed-version]
:local GDate [/system clock get date]
:local Gtime [/system clock get time]
:local GDay [ :pick $GDate 4 6 ]
:local GMonth [ :pick $GDate 0 3 ]
:local GYear [ :pick $GDate 7 11 ]
:local GResult "$GDay $GMonth $GYear"
:local ExportConf ([/system identity get name])
/export compact file="$ExportConf-Version_$version-Date_$GResult-Time_$Gtime"

Who is online

Users browsing this forum: No registered users and 39 guests