Search code examples
windows-7sshautomationputty

How to automate running Linux commands via `ssh` from Windows 7?


Currently I use puTTY, open SSH connection to my Ubuntu server and execute some svn update comment over there.

I want to automate that whole process but executing just a script/batch file.

How can I do that?


Solution

  • I found it myself without using Cygwin - I'm stuck with installing/reinstalling it.

    The answer is using Plink from PuTTY.

    rem Note
    rem ----
    rem 01 Update `plink` to point to `plink.exe` on `your PC`
    rem 02 Update `pkey` to point to `private key` of `remote server`
    rem (the end)
    
    set plink="Path\To\PuTTY\plink.exe"
    set user=<your user>
    set server=<remote server>
    set pkey="Path\To\YourPrivateSSHKey.ppk"
    set pass=<your pass>
    
    set run=%plink% -v -pw %pass% -i %pkey% %user%@%server%
    
    rem sample run command
    set cmd=svn update /var/www/MyWeb
    
    %run% %cmd%
    rem (the end)
    

    Hope that helps