[AppleScript] Command after "ssh user@host"...{newbieQ}

Discussion in 'Mac Programming' started by iBroken, Sep 4, 2011.

  1. iBroken, Sep 4, 2011
    Last edited: Sep 4, 2011

    iBroken macrumors newbie

    Jul 17, 2011

    i've a script that i'm using a lot to connect to my server its simple, i've server with setting no-password SSH, so its like this

    tell application "Terminal"
    do script "ssh user@host"
    end tell
    i want to make a command as soon as my Mac connect to the server, if i write new "do script" line, it will be performed locally on my Mac in other terminal window, so what to do to make my server do this command after the ssh connect ?
  2. jiminaus macrumors 65816


    Dec 16, 2010
    I so wish the formatting controls were disabled on this forum. :mad:
  3. pilotError macrumors 68020


    Apr 12, 2006
    Long Island
    You wouldn't do ssh to run a command on the remote host, you would use rsh (remote shell).

    Go into terminal and do "man rsh"

    Just remember that you get a bare shell and bare PATH variables when you do an rsh. You need to setup the login/profile/whatever else you need to setup the environment in order to run your command.

    Typically, you would create a shell script that contains all setup and runs the command your looking to run.

    If your just doing things like cp or mv, etc..., you can just call it with the full path
    rsh -l user remotehost /bin/cp /home/myname/myfile /destination

    Since your using no password, I assume you have the trust setup already auth.conf??? I forget which file you set on the remote.

    I had some code laying around, but I can't locate just now, otherwise I'd post a real example.
  4. willieva macrumors 6502

    Mar 12, 2010
    To run "script" on a remote computer, just use:
    ssh user@host ./script

    This assumes script is in your home directory and is executable. Otherwise you'd type:
    ssh user@host sh ./script

    For example, to make sure the ssh command is being run where you want it to be, just type:
    ssh user@host hostname

    You can setup ssh agents and keys if you want to be able to login without typing passwords.

    ssh is the secure remote shell replacement for rsh. It's quite possible rsh doesn't work, many systems have this turned off now.

Share This Page