Help: SSH (do shell script)

Hello, everyone. This is my first post here and I’m fairly new to AppleScript as a whole. What I’m trying to do is open an SSH session with a remote Mac in order to run some code. I am running into an issue via (do shell script) that’s otherwise, not really an issue via Terminal activation. The issue is regarding the password prompt for the SSH session. I get this error :

Because it repeats three times, I’m thinking it’s result of failed password attempts, but I’m not sure what my script is trying to put in there. Here is the SSH portion of my AppleScript :


# Gather SSH Credentials
if the button returned of Dialog_2 is "Continue" then
	set AdminName to ""
	set Dialog_4 to display dialog "Admin name:" default answer ""
	set AdminName to text returned of Dialog_4
	set PassKey to ""
	set Dialog_5 to display dialog "Admin Password:" default answer "" with hidden answer
	set PassKey to text returned of Dialog_5
end if

# Open SSH Session
set ssh to (do shell script "ssh " & AdminName & "@" & HostName & "mydomain.com")

try
	if ssh contains "yes/no" then
		(do shell script "yes")
	else
		(do shell script PassKey)
	end if
end try

Any help here would be greatly appreciated. Thank you!

ALSO : I can’t use a key and I don’t want to use expect. I can get this to work if I call Terminal, but not in the AppleScript shell.

Model: 15" Retina MacBook Pro
AppleScript: 2.2.4
Browser: Safari 537.36
Operating System: Mac OS X (10.8)

Hello.

You can’t do it like that, because the do shell script process dies, it is hard to communicate with that way.

A do shell script, is a single process not connected to a tty device, in other words without any direct possibility for interactivity. What you may do, is to invoke the do shell script with administrator privileges, effectively having sudo rights while executing it.

So, if you want to do this, from a do shell script, then you’d better generate a certificate, and log in via that instead of a password. (You say Expect is not an option, but that is something I believe would have worked).

Maybe you’re better off using the Terminal.

Thank you for the reply. I might just do it in a Terminal window. At least I can watch it do its thing from there.

It is less fuss. (At least as long you don’t want to use certificates for it.) :slight_smile:

I can’t use certs because it has to be able to make a connection from anywhere to anywhere so I have no reliable place to store them. :confused:

I’m using the expect command for remote ssh commands using do shell script. An example can be found here