how can save mac address in a comment after login

how can save mac address in a comment after login , hotspot user
thanks

#here we exclude default-trial user or else the script won’t excecute the last line
:foreach i in=[/ip hotspot user find where name!=default-trial] do={
:local uptime [/ip hotspot user get number=$i uptime];
#if an user have 00:00:00 uptime means it’s not connected right? then…
:if ($uptime=00:00:00) do={
:log info “User$i Not Connected”} else={
#i don’t know where do you want to add the comments so i did it right there in /ip hotspot user just as an example
:put [/ip hotspot user set number=$i comment=[/ip hotspot user get number=$i mac-address]]}
}

hope it helps :wink:

Cleaned up the script. Code tags, tabs, if section and removed not needed ;

:foreach i in=[/ip hotspot user find where name!=default-trial] do={
	:local uptime [/ip hotspot user get number=$i uptime]
	#if an user have 00:00:00 uptime means it's not connected right? then...
	:if ($uptime=00:00:00) do={
		:log info "User$i Not Connected"
	} else={
		#i don't know where do you want to add the comments so i did it right there in /ip hotspot user just as an example
		:put [/ip hotspot user set number=$i comment=[/ip hotspot user get number=$i mac-address]]
	}
}

Shorten some and set the comment, not just show it:

/ip hotspot user 
:foreach i in=[find where name!=default-trial] do={
	:local uptime [user get number=$i uptime]
	#if an user have 00:00:00 uptime means it's not connected right? then...
	:if ($uptime=00:00:00) do={
		:log info "User$i Not Connected"
	} else={
		set number=$i comment=[get number=$i mac-address]]
	}
}

thank you I’ll try to this script

but I have another script use it in a (On login) tab in this path (( ip > hotspot > User Profiles > Scripts > On login ))

:local a $user
:local m [/ip hotspot active get [find user=$a] mac-address]
:log info message=("Prueba: ;$a; ;$m;");
/ip hotspot user set $a mac=$m;

but this script add MAC in MAC address field not in a comment, Can we make some changes rules in this script so that put MAC in a comment?

thanks so much

if On login works as i think it does, you´ll just need to change this:
/ip hotspot user set $a mac=$m;

for this:
/ip hotspot user set $a comment=$m; (cause you mean a comment right there in /ip hotspot user right?)

let us know.

Thanks @Jotne but the shortened version of my script didn’t worked out for me, even when i added : and [ to → set number=$i comment=[get number=$i mac-address]]

thaaaaaaaaaanks so much @JaviGL93
exactly this is what I wanted, and used this script and do what I wanted

another question please

the script added MAC in a comment but deleted old comment, Is it possible to add comment not replace comment?

All can be reduced to:

:local mac $"mac-address"
:log info "Prueba: $user $mac"
/ip hotspot user
:local comentario [get $user comment]
set $user comment="$mac - $comentario"

And is better add previous comment later than first, for read reason…

And I think you want keep comments for history of MACs?

yes, I used last script and old comment still exists :slight_smile: , working fine

@JaviGL93 thanks
and
@rextended thanks so much for reduce script :slight_smile:

On the mention of Date, I have another question :confused:

before write this post I wanted to have script save comment contain MAC and date and time user login
Can this script be developed to contain MAC and time (year, month, day, hour and minute) after user logged?

yes, but the comment over time can increase too much in size…

The date is “like” ISO format: “00:AA:BB:CC:DD:EE 2022-03-18 16:25”

:local arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
:local curdatetime "$[/system clock get date] $[/system clock get time]"
:local ldate ("$[:pick $curdatetime 7 11]-$($arrMonths->[:pick $curdatetime 0 3])-$[:pick $curdatetime 4 6] $[:pick $curdatetime 12 14]:$[:pick $curdatetime 15 17]")

:local mac $"mac-address"
:log info "Prueba: $user $mac"
/ip hotspot user
:local comentario [get $user comment]
set $user comment="$mac $ldate - $comentario"

WOW
Special Thanks @rextended
Thanks to all

month not added in a comment

“00:AA:BB:CC:DD:EE 2022–18 16:25”

RouerOS version? The script is for 6.4x, (probably) work for 7.x

Try this on terminal, must write correctly the date:

{
:local arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
:local curdatetime "$[/system clock get date] $[/system clock get time]"
:local ldate ("$[:pick $curdatetime 7 11]-$($arrMonths->[:pick $curdatetime 0 3])-$[:pick $curdatetime 4 6] $[:pick $curdatetime 12 14]:$[:pick $curdatetime 15 17]")
:put $ldate
}

Without month name/value conversion:

{
:local curdatetime "$[/system clock get date] $[/system clock get time]"
:local ldate ("$[:pick $curdatetime 7 11]-$[:pick $curdatetime 0 3]-$[:pick $curdatetime 4 6] $[:pick $curdatetime 12 14]:$[:pick $curdatetime 15 17]")
:put $ldate
}

do not personalize month names, must be on english,
if the output of the last is not
2022-mar-18 16:54
but something like
2022-Mar-18 16:54
or
2022-MAR-18 16:54
the array of month names must be changed accordingly.

yes all working now

after last edit print with this format :
2022-mar-18

thaaaaaaaaanks

(Probably) fixed for 7.x month name/number conversion:

:local arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
:local curdatetime "$[/system clock get date] $[/system clock get time]"
:local ldate ("$[:pick $curdatetime 7 11]-$($arrMonths->[:pick $curdatetime 0 3])-$[:pick $curdatetime 4 6] $[:pick $curdatetime 12 14]:$[:pick $curdatetime 15 17]")

:local mac $"mac-address"
:log info "Prueba: $user $mac"
/ip hotspot user
:local comentario [get $user comment]
set $user comment="$mac $ldate - $comentario"