script send email as user login into routerboard

Also working fine, but there is no body and subject :frowning:

I have a new way to do that without full script.

Is it possible to send by eamil only new files once written?

Can you post the script ore solution on the forum please?
Thanks

yes,


just creat a new action under logging like our friends said in this post. But instead of email the rule, store it to the disk.

Now I would like to email this file only if it’s new (maybe by looking at ‘‘creation date’’)



Actually I run both, email when rule is triggered it send an email, plus, send a copy of the file by eamil every day.


it works but can be more reliable I think.

i realized that there is not much information when it stored to the disk. So the solution is not very usefull.

Hi guys!
I used this script:
:log info message=(“Start Check Logged Users”);
:local tmpAllTheUsersLogged value=[/user active find];
:if ([:len $tmpAllTheUsersLogged] > 0) do={
:local tmpMessage value=“”;
:foreach tmpArrayItem in=$tmpAllTheUsersLogged do={
:set $tmpMessage value=($tmpMessage.[/user active get value-name=name $tmpArrayItem]." logged from “.[/user active get value-name=when $tmpArrayItem].” via “.[/user active get value-name=via $tmpArrayItem].”\r\n");
};
:set $tmpMessage value=(“Logged user(s) “.[/system clock get date].” “.[/system clock get time].”\r\n”.$tmpMessage);
:if ($cluEmailSent != “true”) do={
:log info message=$tmpMessage;
/tool e-mail send from=“clu.script@routerboard.local” to=“your@mail.it” subject=("Logged user(s) report of “.[/system clock get date].” ".[/system clock get time]) body=$tmpMessage;
:global cluEmailSent value=“true”;
};
} else={
:global cluEmailSent value=“false”;
};
:log info message=(“Check Logged Users End”);

Also add to scheduler:
:global cluEmailSent value=“false”;

But my router sends me same email with same user login each time the script starts.
How to fix this?

Is it possible to change the script to send an email only once when the user logs in and that’s it, and not send these messages anymore that he is logged in or active?

Its possible by setting an gloabal variable with history of the user logged inn, but would be some complicated.

You can also look at my Splunk project in my signature. There you can see in an external app all logged in user/when and get it nice graphed.

I Delete :global cluEmailSent value=“false”; in the script and everything looks fine to me.
I only get 1 email
Greatings

Hi plisken.
Can you please share with me your script? An identical script cannot work for you, but for me not.

This is the working script, but don’t forget to setup the email settings in “tools” “email”.

:log info message=("Start Check Logged Users");
:local tmpAllTheUsersLogged value=[/user active find];
:if ([:len $tmpAllTheUsersLogged] > 0) do={
:local tmpMessage value="";
:foreach tmpArrayItem in=$tmpAllTheUsersLogged do={
:set $tmpMessage value=($tmpMessage.[/user active get value-name=name $tmpArrayItem]." logged from ".[/user active get value-name=when $tmpArrayItem]." via ".[/user active get value-name=via $tmpArrayItem]."\r\n");
};
:set $tmpMessage value=("Logged user(s) ".[/system clock get date]." ".[/system clock get time]."\r\n".$tmpMessage);
:if ($cluEmailSent != "true") do={
:log info message=$tmpMessage;
/tool e-mail send from="youreemail@test.com" to="youremail@test.com" subject=("Logged user(s) report of ".[/system clock get date]." ".[/system clock get time]) body=$tmpMessage;
:global cluEmailSent value="true";
};
} else={
:global cluEmailSent value="false";
};
:log info message=("Check Logged Users End");

Same script, with tabs and without not needed semicolon.


:log info message=("Start Check Logged Users")
:local tmpAllTheUsersLogged value=[/user active find]
:if ([:len $tmpAllTheUsersLogged] > 0) do={
	:local tmpMessage value=""
		:foreach tmpArrayItem in=$tmpAllTheUsersLogged do={
			:set $tmpMessage value=($tmpMessage.[/user active get value-name=name $tmpArrayItem]." logged from ".[/user active get value-name=when $tmpArrayItem]." via ".[/user active get value-name=via $tmpArrayItem]."\r\n")
		}
	:set $tmpMessage value=("Logged user(s) ".[/system clock get date]." ".[/system clock get time]."\r\n".$tmpMessage)
	:if ($cluEmailSent != "true") do={
		:log info message=$tmpMessage
		/tool e-mail send from="youreemail@test.com" to="youremail@test.com" subject=("Logged user(s) report of ".[/system clock get date]." ".[/system clock get time]) body=$tmpMessage
		:global cluEmailSent value="true"
	}
} else={
	:global cluEmailSent value="false"
}
:log info message=("Check Logged Users End")

Hi, how to use iCloud or Gmail for notifications ?
I`m new user here, thanks!

Google search is a nice tool to find these types of stuff.

Example here:
https://wiki.mikrotik.com/wiki/Manual:Tools/email

Thank you, but this script does not work for me as it should.
Though I delete: global cluEmailSent value = “false”; the email is still sent every time the script is triggered and letters are sent until the user logs out.
Probably it’s time to tie up with the idea of ​​a script and go look for other options.
Thank you guys for your attention.