Is there a way I can shutdown a Linux box (CentOS) from a batch file on a Windows machine (win 2012 Server)?
32 Answers
The final solution I went with was using PLink.exe which is installed in the puTTY package, then create a batch file:
StopServer1.bat
"C:\Program files (x86)\puTTY\plink.exe" -ssh -root@Server1 -pw <password> shutdown -h now There are more elaborate solutions, but a cheap and cheerful one is to use a flag file in a shared directory and a task which checks its existence, eg:-
if [ -r {shared-dir}/ShutDown ]; then rm {shared-dir}/ShutDown; shutdown -h now; fiYou can run this either in a loop with a sleep 60 (say) command, or as a single command in a script run repeatedly from cron.
Your windows server simply creates {shared-dir}/ShutDown whenever it wants a shut-down.
I hope it goes without saying that {shared-dir} must be writeable from the Linux system, to allow the deletion which both prevents a reboot loop and enables the Windows server to know when the shut-down request has been received and acted on.