HT2488: Mac Basics: Automator

Learn about Mac Basics: Automator
New to Automator

Q: Want to run Terminal directly with a prewritten script with Automator

Hello all.

 

I want to SSH via terminal, each time I have to write the port number, the domain...etc...is it possible to do all this with a single click using Automator? am using Snow Leopard  10.6.8

 

Thanks

Posted on Feb 29, 2012 10:12 AM

Close

Q: Want to run Terminal directly with a prewritten script with Automator

  • All replies
  • Helpful answers

  • by BobHarris,

    BobHarris BobHarris Feb 29, 2012 10:23 AM in response to New to Automator
    Level 6 (19,662 points)
    Mac OS X
    Feb 29, 2012 10:23 AM in response to New to Automator

    Why not create a shell script to just execute the ssh you want?

     

    #!/usr/bin/env bash

    ssh -p 12345 username@remote.host.domain.name

     

    save as a file with a name you like and make the file executable

     

    chmod +x name.of.the.script.you.created

     

    You could have different shell scripts for different systems you are trying connect to.

     

    Now I like to use iTerm.sf.net which allows me to maintain a set of bookmarks with stored ssh commands so I can start an iTerm terminal tab that automatically issues the needed ssh command that connects to the remote system.  iTerm even lets you assign hot keys to books marks (Command-Control-a, cmd-ctl-b, cmd-ctl-c, etc...)

  • by New to Automator,

    New to Automator New to Automator Feb 29, 2012 10:35 AM in response to BobHarris
    Level 1 (0 points)
    Feb 29, 2012 10:35 AM in response to BobHarris

    Thank you Bob!!

     

    but if you could explaing to me how to create a shell script.

  • by BobHarris,

    BobHarris BobHarris Feb 29, 2012 10:47 AM in response to New to Automator
    Level 6 (19,662 points)
    Mac OS X
    Feb 29, 2012 10:47 AM in response to New to Automator

    nano name.of.the.script

    ... enter your script starting with #/usr/bin/env bash on the very first line...

    Control-O Control-X to save and exit nano

     

    chmod +x name.of.the.script

     

    ./name.of.the.script # to invoke the script

     

    Suggest against using TextEdit (creates more problems then it is worth to untangle).  If you must use a GUI text editor, then download the free TextWrangler (google will find it).

     

    I just remembered another trick you can use.  If you name the file something.command (the important thing being .command as the end of the file name), and you have made it executable using the

     

    chmod +x something.command

     

    then you can double click on the file, and it will launch Terminal, then exeucte the commands in the something.command file.  Of course the 'something' can be anything you want as long as it ends in .command

     

    You might like this better.

     

    Message was edited by: BobHarris

  • by twtwtw,

    twtwtw twtwtw Feb 29, 2012 10:53 AM in response to BobHarris
    Level 5 (4,935 points)
    Feb 29, 2012 10:53 AM in response to BobHarris

    Hey, it's the 21st century already!  unless you grew up with nano and are used to command line text editing, download TextWrangler and use that.  it's a much more user-friendly environment for people who are accustomed to point-and-click text editing apps.  You could even use TextEdit, so long as you make sure you're editing in plain text (not rich text) mode.

     

    nano - unix geektility...

  • by BobHarris,

    BobHarris BobHarris Feb 29, 2012 11:42 AM in response to twtwtw
    Level 6 (19,662 points)
    Mac OS X
    Feb 29, 2012 11:42 AM in response to twtwtw

    TextEdit has recently been guilty of applying a quarantine xattr, so I would stay away from TextEdit.

  • by Linc Davis,

    Linc Davis Linc Davis Feb 29, 2012 12:02 PM in response to New to Automator
    Level 10 (208,037 points)
    Applications
    Feb 29, 2012 12:02 PM in response to New to Automator
  • by BobHarris,

    BobHarris BobHarris Feb 29, 2012 12:39 PM in response to Linc Davis
    Level 6 (19,662 points)
    Mac OS X
    Feb 29, 2012 12:39 PM in response to Linc Davis

    Or even search over at MacUpdate.com for ssh helpers

    <http://www.macupdate.com/find/mac/ssh>

  • by Cole Tierney,

    Cole Tierney Cole Tierney Feb 29, 2012 12:52 PM in response to New to Automator
    Level 4 (1,376 points)
    Feb 29, 2012 12:52 PM in response to New to Automator

    I would recomend using a ~/.ssh/config file. I'm sure it would be helpful with all the suggestions here. Create ~/.ssh/config with somthing like the following:

    Host alice
         Hostname some.domain.name
         User yourusername
    
    Host bill
         Hostname remote.host.domain.name
         User username
         Port 12345
    
    

    Then to log in:

    ssh alice

    or

    ssh bill

    To see all the rest of the options that can be set for each host entry:

    man ssh_config