[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

    Joined:
    Jul 17, 2011
    #1
    Hi

    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

    PHP:
    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

    jiminaus

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

    pilotError

    Joined:
    Apr 12, 2006
    Location:
    Long Island
    #3
    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
    ie.
    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

    Joined:
    Mar 12, 2010
    #4
    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