Net RPC Shutdown scripted?
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
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:
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
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]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.targetIt 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
Re: Net RPC Shutdown scripted?
Read an environment file in the unit?
https://stackoverflow.com/a/66167271
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
Re: Net RPC Shutdown scripted?
So I tried to modify my service file based on that suggestion to:
But now it hangs my entire server waiting for an input from the named pipe instead of running quietly in the background
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.targetReturn to "General discussion"
Jump to
- Community
- General discussion
- Announcements
- Other languages
- Deutsch
- Español
- Français
- Italiano
- Nederlands
- 日本語
- Polski
- Português
- Русский
- Türkçe
- User groups and events
- Raspberry Pi Official Magazine
- Using the Raspberry Pi
- Beginners
- Troubleshooting
- Advanced users
- Assistive technology and accessibility
- Education
- Picademy
- Teaching and learning resources
- Staffroom, classroom and projects
- Astro Pi
- Mathematica
- High Altitude Balloon
- Weather station
- Programming
- C/C++
- Java
- Python
- Scratch
- Other programming languages
- Windows 10 for IoT
- Wolfram Language
- Bare metal, Assembly language
- Graphics programming
- OpenGLES
- OpenVG
- OpenMAX
- General programming discussion
- Projects
- Networking and servers
- Automation, sensing and robotics
- Graphics, sound and multimedia
- Other projects
- Media centres
- Gaming
- AIY Projects
- Hardware and peripherals
- Camera board
- Compute Module
- Official Display
- HATs and other add-ons
- Device Tree
- Interfacing (DSI, CSI, I2C, etc.)
- Keyboard computers (400, 500, 500+)
- Raspberry Pi Pico
- General
- SDK
- MicroPython
- Other RP2040 boards
- Zephyr
- Rust
- AI Accelerator
- AI Camera - IMX500
- Hailo
- Software
- Raspberry Pi OS
- Raspberry Pi Connect
- Raspberry Pi Desktop for PC and Mac
- Beta testing
- Other
- Android
- Debian
- FreeBSD
- Gentoo
- Linux Kernel
- NetBSD
- openSUSE
- Plan 9
- Puppy
- Arch
- Pidora / Fedora
- RISCOS
- Ubuntu
- Ye Olde Pi Shoppe
- For sale
- Wanted
- Off topic
- Off topic discussion