Community discussions

MikroTik App
 
aliboy
newbie
Topic Author
Posts: 35
Joined: Thu Aug 01, 2019 9:09 pm

Scripting | displayed results save to file

Sun May 02, 2021 5:20 pm

HI,
The script below creates the file but it is empty. I would like the results to be saved on the file aside from just showing on the terminal. Is that possible?

:foreach i in=[ /ip/hotspot/user print file=aaaaaaaaaaa detail as-value where comment=admin ] do={:put (("username: " . $i->"name") ." " . "password: " . ($i->"password"));}

username: 649c8 password: 26927
username: dexsm password: 46789
username: 4btjb password: 93555
username: ua67a password: 97954
username: t5w6n password: 65495
username: rr2wm password: 25265
username: kwmd3 password: 73223
username: 9yexa password: 43636
username: bnkxv password: 84966
username: xrmpb password: 88595
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scripting | displayed results save to file  [SOLVED]

Sun May 02, 2021 11:39 pm

yes, is possible but your script can't do that.

use this:
:global filecontent ""
/file print file="userexport.txt"
:delay 1s

/ip hotspot user
:foreach i in=[find where comment="admin"] do={
 :set filecontent ($filecontent."username: ".[get $i name]." password: ".[get $i password]."\r\n")
 :put ("username: ".[get $i name]." password: ".[get $i password])
}

/file set "userexport.txt" contents=$filecontent


remove this line (or comment with # at start of line) for not display on terminal but only save on file.
:put ("username: ".[get $i name]." password: ".[get $i password])
Last edited by rextended on Mon May 10, 2021 9:55 am, edited 2 times in total.
 
aliboy
newbie
Topic Author
Posts: 35
Joined: Thu Aug 01, 2019 9:09 pm

Re: Scripting | displayed results save to file

Mon May 10, 2021 5:22 am

/file set "userexport.txt" contents=$filecontent

enclosing the filename into double-quotes completed the code.

Thank you very much!!!!!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scripting | displayed results save to file

Mon May 10, 2021 9:55 am

/file set "userexport.txt" contents=$filecontent

enclosing the filename into double-quotes completed the code.

Thank you very much!!!!!
Thanks, I add the forgetted "

Who is online

Users browsing this forum: No registered users and 63 guests