How do I run these terminal commands in AppleScript Editor?

Discussion in 'Mac Programming' started by pcs are junk, Feb 16, 2010.

  1. pcs are junk macrumors 65816

    Joined:
    Sep 28, 2009
    #1
    Hi guys, I want to run the following script in AppleScript editor, but its not letting me. Can anyone fix this up for me? Thanks. Also if you want credit for helping me, just leave your codename/hacker name, or just say you want to use your MacRumors name. First correct answer gets credit. Thank you!

    do shell script "ssh root@192.168.1.33"
    [password]
    alpine
    do shell script "rm /private/var/Keychains/keychain-2.db"
     
  2. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #2
    Each time AS calls "do shell script" it creates a new shell, so to speak. So if you need a multiline script you would do something like this:

    Code:
    do shell script "ssh root@192.168.1.33; [password]; alpine; rm /private/var/Keychains/keychain-2.db"
    
    You might need to fiddle with the password, though.

    mt
     
  3. pcs are junk thread starter macrumors 65816

    Joined:
    Sep 28, 2009
    #3
    this is the error i am receiving when i do that code.

    error "Pseudo-terminal will not be allocated because stdin is not a terminal.
    ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
    Permission denied, please try again.
    ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
    Permission denied, please try again.
    ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
    Permission denied (publickey,password,keyboard-interactive).
    sh: [password]: command not found
    sh: alpine: command not found
    rm: /private/var/Keychains/keychain-2.db: No such file or directory" number 1
     
  4. fredthefool macrumors newbie

    Joined:
    Jun 4, 2008
    #4
    Not shure about the specs of the remote box, you're trying to log in, but if it's a mac, it's highly possible that the root account is not active. That's the default setting in OS X. In that case, you probably better try another administrator account.
    This could be the cause for the failure logs on "Permission" as well as for the obviously missing path to the "alpine" command. (Did you test your/root's path to it via a ssh-session in Terminal with "which alpine" ?)
    And i read the output as if you would have typed in "[password]" exactly like that, but i'm shure mysterytramp meant you to type in the actual password of the root account instead. (No offence!)
    Another helpful option for the ssh command could be "-T", which will suppress creation of a pseudo terminal.
     
  5. pcs are junk thread starter macrumors 65816

    Joined:
    Sep 28, 2009
    #5
    hi guys, maybe if i tell you what im trying to do, then you can give me the code. so basically what im trying to do, is ssh into root on my ipod touch, with the password being alpine, which is default by apple. then what i'm trying to do is enter a command to delete the file. these all work in terminal, but i cant get them to work in applescript. thanks alot!
     
  6. ViViDboarder macrumors 68040

    ViViDboarder

    Joined:
    Jun 25, 2008
    Location:
    USA
    #6
    How about a shebang?

    Or is that not needed with an Applescript?

    You could also just create a .sh file and skip the Applescript part.

    Or you can create the .sh file and then just execute it with Automator and save it.
     
  7. pcs are junk thread starter macrumors 65816

    Joined:
    Sep 28, 2009
    #7
    I really don't know much about AppleScript, I would just really like to be able to run these codes for an application I'm making. Please help! I don't know what to do!!! I think the problem is with the line l 'do shell script "ssh@192.168.1.33"'. Because I tried that alone and got an error. Please somebody help!
     
  8. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #8
    Your first problem is that there is no way to provide the password after you have started a shell in AppleScript. So you have two choices there: either include the password in the ssh url (root:password@192.168.1.33) or setup things so that you don't need a password to ssh from that computer to the other one (you can do this with public/private keys).

    Then you are going to run into the next problem that you subsequent operations are not going to go across the ssh connection (since that is a separate subprocess). So you need to work that into the same process like this:
    Code:
    do shell script "ssh root:password@192.168.1.33 'alpine; rm /private/var/Keychains/keychain-2.db'". Of source this assumes that the alpine binary exists on the remote computer, and is in the path for the root user. And I think that you probably want to interact with alpine there, rather than just running it, so you are going to have a problem there to.
     
  9. pcs are junk thread starter macrumors 65816

    Joined:
    Sep 28, 2009
    #9
    this is the error i am getting when i use that code.

    ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
    Permission denied, please try again.
    ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
    Permission denied, please try again.
    ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
    Permission denied (publickey,password,keyboard-interactive).
     
  10. ViViDboarder macrumors 68040

    ViViDboarder

    Joined:
    Jun 25, 2008
    Location:
    USA
    #10
    You need a space...

    You'll want
    Code:
    ssh root@192.168.1.33
     
  11. pcs are junk thread starter macrumors 65816

    Joined:
    Sep 28, 2009
    #11
    sorry typo, i meant to say "do shell script "ssh root@192.168.1.33"

    im having a problem now with something about ssh-askpass. i need to download that some where, or if someone can tell me how to make it, it has to be put in macintosh hd/usr/libexec/
     

Share This Page