Sunday, January 23, 2011

Execute a remote command on a Mac from Windows

What's the easiest way to execute a single command on a Mac from a remote Windows machine, via batch?

I would like something that works without a preset configuration (like SSH credentials) on either machines, as I need to apply this on several Win/Mac pairs (yes, I know it's less secure, but it's not relevant to my needs).

The macs all have a common user/password (in fact, they are on the same domain), and I want to automate this as painlessly as possible.

  • I suppose on the windows server you could use putty/plink to connect to the mac via SSH (assuming that ssh is open and running).

    First use putty to create a shared key on the windows server and you'll put that on the mac... probably authorized_keys file. Don't set a password on the key.

    Then, you could use plink to login and run a command using that key.

    Check out: http://tartarus.org/~simon/putty-snapshots/htmldoc/Chapter7.html#plink-usage-batch "7.2.2 Using Plink for automated connections"

    Putty is available here: http://www.chiark.greenend.org.uk/~sgtatham/putty/

    ripper234 : I would like something that doesn't force me to setup SSH public keys, because i need to set them up from/to multiple computers.
    From Imo
  • Anything like this, whether it's to a Mac or a Linux machine I use WinSCP, as it has good scripting support and is very easy to use. Just set up public keys for SSH to eliminate the password prompt.

    Edit

    Here's a batch file using PuTTY if you don't mind the password issue.

    @echo off
    echo command1; command2; commandn; exit>tmp_file
    putty -ssh user@taget_machine -pw password -m tmp_file
    
    ripper234 : I would like something that doesn't force me to setup SSH public keys, because i need to set them up from/to multiple computers.
    John Gardeniers : You don't have to but then you have the problem of having to enter the password.
    ripper234 : I would like a way to automate entering the password. I don't mind storing the user/pass in the batch script.
    John Gardeniers : @ripper234, see the edit to my answer.
    ripper234 : Thanks, looks better

0 comments:

Post a Comment