We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

3 posts • Page 1 of 1
abishur
Posts: 4505
Joined: Thu Jul 28, 2011 4:10 am

Net RPC Shutdown scripted?

Tue Jul 19, 2022 5:24 am

I was using a pi 4 to run docker and wanted to shutdown a windows PC from within the dock. Unfortunately the container doesn't have samba common installed so I can't use net rpc shutdown from within container.

My end goal is to set up a system daemon that will listen for an ip address being written to the named pipe and use whatever comes into that pipe to execute the command

Code: Select all

net rpc shutdown -t 30 -C 'Shutting Down Now' [USER]%[PASSWORD] -I [IP_ADDRESS]
I was going to hard code in username and password, I know not the best security and if anyone knows a way to store that information more securely I'm all ears, but I'm trying to focus on one issue at a time :lol:

For the system daemon I was thinking about creating it like this:

Code: Select all

[Unit]
Description=Listen for windows shutdown commands via pipe
[Service]
Restart=always
User=nobody
Group=nogroup
ExecStart= net rpc shutdown -t 30 -C 'Shutting Down Now' [USER]%[PASSWORD] -I magic happens here
[Install]
WantedBy=multi-user.target
But I'm stuck at the magic happens here bit. I was able to do this with wakeonlan since you can use -f to specify a file that has the mac address to send a magic packet to, but I'm missing that last crucial step to make it work with net rpc shutdown. Does anyone have any ideas?
It doesn't have to be a system daemon in the end, but I know I only want to pass in the ip address so if somehow my named pipe was hijacked anyone trying to send a command would have it fail as it immediately tries to execute the net rpc shutdown command

epoch1970
Posts: 8664
Joined: Thu May 05, 2016 9:33 am

Re: Net RPC Shutdown scripted?

Tue Jul 19, 2022 9:23 am

Read an environment file in the unit?
https://stackoverflow.com/a/66167271
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

abishur
Posts: 4505
Joined: Thu Jul 28, 2011 4:10 am

Re: Net RPC Shutdown scripted?

Tue Jul 26, 2022 4:59 pm

So I tried to modify my service file based on that suggestion to:

Code: Select all

[Unit]
Description=Listen for windows shutdown commands via pipe
StartLimitIntervalSec=5
StarLimitBurst=5
[Service]
Restart=always
RestartSec=1s
User=nobody
Group=nogroup
EnvironmentFile=/mnt/vmStorage/apps/homeassistant/config/winwolpipe
ExecStart= net rpc shutdown -f -t 10 -C 'Will this shut things down?' -U user%%password -I ${var1}
[Install]
WantedBy=multi-user.target
But now it hangs my entire server waiting for an input from the named pipe instead of running quietly in the background

3 posts • Page 1 of 1

Return to "General discussion"

AltStyle によって変換されたページ (->オリジナル) /