Running shell scripts from Windows Andrew Mallett | September 2013

If you use both Linux and Windows systems, you may be interested in running scripts on the server without having to manually ssh all the time. Previously I have looked at remotely booting a server using Wake-on-LAN and remote server shutdown. This article covers running scripts using Windows batch files.

Running shell scripts from Windows

In the above illustration a number of batch files have been added as Start menu shortcuts, to perform various functions on a remote FreeBSD Unix server. These batch files use a third-party utility called Plink (PuTTY-link) which harnesses the power of ssh without needing to log in and run scripts manually. Plink was developed by the same team who created the awesome PuTTY client and can be downloaded, together with other useful utilities from Simon Tatham's website.

Each function requires a pair of files: a batch file and a text file, plus the plink.exe Windows executable. Firstly the batch file invokes plink to perform the ssh log-in, which in turn runs the command(s) in the text file on the remote server. Here's an example..

The batch file, gothwrite.bat:

f:\progs\plink -ssh andym@goth -pw mypassword -m f:\progs\gothwrite.txt

The text file, gothwrite.txt:

sudo /sc/writesomething.sh

To keep things simple I use the same name for the batch and text files and they all live together in the \progs directory which is in the system path on my Windows box.

The writesomething.sh sitting on the remote server has been designed to perform some function and has been tested on the server before running it remotely. Depending on server permissions, the script may also need sudo to work properly.

The full set of plink command switches can be seen by simply typing plink in a command prompt window or going to the Plink command options page.



Comments (0)

E-mail (Will not appear online)
;-) :-) :-D :-( :-o :-O B-) :oops: :-[] :-P
To prevent automated Bots form spamming, please enter the text you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
This comment form is powered by GentleSource Comment Script. It can be included in PHP or HTML files and allows visitors to leave comments on the website.

Throwaway Email   Temporary Email   Temporary Email