WOL (Rule/Script?)

Hi,

I need some help again :slight_smile:.
Is it possible to define a rule, if I boot a PC and Link is up to send a WOL-Package on the Server?
And the other Way around, If Link is down for some time than shut down the server?

LG stonie

I’d use netwatch for this. Assign that PC a static IP or a static DHCP lease and just monitor that address.
Then put your scripts in the up/down actions.
Done.
-Chris

Thank you :slight_smile:.
WOL Script was no Problem, but for shutdown the Server I have currently no idea.
The next Problem Is, can I check with netwatch more than One Pc?
I have 3-4 PC’s I want to check, and if one of them is on, I want WOL the Server.
And if all of them are off, then I want shutdown the Server.

Lg stonie

Ah - that’ll get tricky with more computers.
I’d set up a scheduler to run every n minutes which checks all the related netwatch items.
If all are down, trigger a script which puts your server into sleep mode.

Since there is no Sleep-on-Lan package, you need to find out how your server can be shut down.
If it’s a unixoid system, I’d go for ssh and let it execute a command. like

/sys ssh server.ip user=serviceuser command="systemctl hibernate"

Then you need to add a user account to your router matching the remote account, add the SSH key for it and that should be it.
-Chris

Okay I get the command run for my normal user on debian stretch (I think I don’t like systemctl :smiley:).
And I get passwordless access to the server over putty with ssh keys from my windows machine.
But I don’t get it work from the mikrotik router.

The generatet key from putty I can’t import in mikrotik. Everytime error (can’t import key).
Am I on the right point, under User Tab → ssh key → and than import?
User on Mikrotik is my admin user, but has the same name as on my debian server, don’t know if that matters? Is there need for an extra user?
And is this a two way connection? I only want passwordless to my debian, not to my mikrotik.
All the manuals I find are to connect passwordless from Linux machine to mikrotik, but not the other way around.
Or is that the same?

Do you have any hint for me how I get it to work?

I’m one step closer now.
Passwordless connection from mikrotik to server works.
Now I have two working scripts for WOL and shutdown.

The only thing I still need help, how to check the multiple netwatch-items, and trigger the shutdown-script if all are down?
Has anyone a idea how I get that to work?

Setup Global Variables, store the UP/DOWN results in those variables, Query the variables results from the Environment, & act upon it as per requirements.
You can do Multiple IF statement Matching , some thing like (you can further stretch it)

:local dsl1 [/system script environment get [/system script environment find name="VARIABLE1"] value];
:local dsl2 [/system script environment get [/system script environment find name="VARIABLE2"] value];
:if (($dsl1 = "DOWN") && ($dsl2 = "DOWN")) do={

Example:
link

Thanks @aacable,

I needed some time to understand how it works :slight_smile: .
Now I set in Netwatch the global variables for example like that:
:global pc1 “UP”
:global pc1 “DOWN”

and I have a script like that:

:local host1 [/system script environment get [/system script environment find name=“pc1”] value];
:local host2 [/system script environment get [/system script environment find name=“pc2”] value];
:local host3 [/system script environment get [/system script environment find name=“pc3”] value];
:if (($host1 = “DOWN”) && ($host2 = “DOWN”) && ($host3 = “DOWN”)) do={
/sys ssh 192.168.0.10 user=stonie command=“systemctl poweroff”}

And if I run the script within the winbox Terminal the script works fine.
But when I go to the script list and press the Button “Run script” it doesen’t work, also from the scheduler.
Is there any trick to make it work?

Anywhere I read the same Problem, but I don’t find the Thread anymore :frowning: .
Is there a workaround how I can use the ssh public key in a script?
Because in the Terminal it works fine.