Passing RouterOS command output (text) to a variable

Hello All,

I’m new to RouterOS and pretty new when it comes to the scripting part.
I’m having difficulties figuring out how i can assign command output to a local variable.
Lets say i want to receive /system resource print output as mail.

What i do is:

:local rescontent
:set rescontent [/system resource print as-value]
#send email
/tool e-mail send to=“xxxxxxxxxxx@gmail.com” subject=([/system identity get name] . " System Resources " . [/system clock get date]) body=$rescontent tls=yes

But nothing happens. Can you tell me what am i doing wrong?
Thanks!

Have you checked your SMTP settings? Those seen at “/tool e-mail print” I mean. You need to set them to your “from” email’s SMTP server.

Edited: Repeated Comment

Здрасти! / Hi!

I can send mail to whatever address i like using the /tool e-mail send command. Mail servers and credentials are configured correctly. Thats not the problem.

Am i doing everything OK with the variable?

Edited: Repeated comment

This will get you a variable with the resources of the router.


:local rescontent
sys resource monitor file=resources.txt
:set rescontent [/file get [/file find name=resources.txt] contents]

If you are looking for only a specific resource instead of all of the output of /system resource print, it would require a bit more logic in the script to grab what you want.

Thanks a million!
That worked :slight_smile:
But what about if I want to combine the output of two variables in the body of the e-mail message?
Specifying the first variable in the message is body=$rescontent but if i want to add another text output to the mail that is holded by another variable how can i add it alongside the first?

You basically follow the syntax for combining strings. It should look something like this, just like what you have for your subject line:

subject=($rescontent . " Your text here that you want to add.  "  . $anotherVariable )

Thank you very much again! :slight_smile:

some time small wrong setting in the SMTP cause a big problem you can need to save the setting so that you can check the changes at any time.