How to remote Shutdown Linux machine from Windows?

21,637

Solution 1

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

Solution 2

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; fi

You 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.

Share:
21,637

Related videos on Youtube

NickC
Author by

NickC

Updated on September 18, 2022

Comments

  • NickC
    NickC almost 2 years

    Is there a way I can shutdown a Linux box (CentOS) from a batch file on a Windows machine (win 2012 Server)?

    • barlop
      barlop over 9 years
      -1 first look how do you shutdown a linux machine locally(SHUTDOWN COMMAND) then look at how to issue commands remotely(SSH). so ssh to it and issue a shutdown command as root.
    • Ravindra Bawane
      Ravindra Bawane over 9 years
      superuser.com/questions/736665/… Please check out the answers here and then edit your question with any addition information you may need to complete the solution. Yours is a question is pointing at useful information, it just needs a little work on your part to become a really good question.