Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Add Password to Shell Script for ssh

Hi I'm trying to avoid creating ssh keys for this I was hoping to write it all in to applescript.


This is what I have.


I've done lots of searches, but not quite getting the right outcome.


Matt


set ShellS to "rsync -aE --progress --delete --exclude=\"._*\" /Volumes/Images/2014-2015 StudioB@StudioBs-iMac.local:/Volumes/ImagesB/ "


do shell scriptShellS

Mac Pro, OS X Yosemite (10.10.2)

Posted on Apr 7, 2015 7:47 AM

Reply
Question marked as Best reply

Posted on Apr 8, 2015 2:26 AM

You are failing to tell rsync to sync via ssh for one thing.


rsync -aE --progress --delete --exclude="._*" -e ssh /Volumes/Images/2014-2015 StudioB@StudioBs-iMac.local:/Volumes/ImagesB/


You are also using the -E option which will copy files in AppleDouble format then you are attempting to exclude the ._ files which the -E option creates. Beyond these points, attempting to pass a password to ssh via a shell script is problematic.

4 replies
Question marked as Best reply

Apr 8, 2015 2:26 AM in response to MattJayC

You are failing to tell rsync to sync via ssh for one thing.


rsync -aE --progress --delete --exclude="._*" -e ssh /Volumes/Images/2014-2015 StudioB@StudioBs-iMac.local:/Volumes/ImagesB/


You are also using the -E option which will copy files in AppleDouble format then you are attempting to exclude the ._ files which the -E option creates. Beyond these points, attempting to pass a password to ssh via a shell script is problematic.

Apr 8, 2015 2:27 AM in response to Mark Jalbert

Thanks, that did help, I wondered what all those extra files were,


Now searching the net this is where I am at., But I get the error

error "invalid command name \"rsync\"

while executing

\"rsync -a --progress --delete --exclude=\"._*\" -e ssh /Volumes/Images/2014-2015 StudioB@StudioBs-iMac.local:/Volumes/ImagesB/ \"" number 1



set sshPasswd to "PSW"


set ShellS to "rsync -a --progress --delete --exclude=\"._*\" -e ssh /Volumes/Images/2014-2015 StudioB@StudioBs-iMac.local:/Volumes/ImagesB/

expect {

\"Password:\" {

send \"" & sshPasswd & "\\r\"

exp_continue

}

\"yes/no?\" {

send \"yes\\r\"

exp_continue

}

}"


do shell script "expect <<<" & quoted form of ShellS

Apr 8, 2015 6:23 AM in response to MattJayC

I'm going to suggest that you develop and test your shell script/commands in the shell environment before you attempt to incorporate them into AppleScript.

You can use an expect script. The script should spawn the rsync command. Of course, using plain text passwords in a script is a VERY bad idea. While I feel wrapping such a script in AppleScript is unnecessary, Hiroto has/had a number of examples embedding shell scripts within AppleScript on this forum.


Good luck

Apr 8, 2015 9:38 AM in response to MattJayC

Create the ssh keys — that's how this stuff is meant to work, and it avoids having a hard-coded password. Either create the plain ssh keys, or preferably create keys with passphrases. There are various examples of using ssh-keygen around the 'net, though the details can vary by the particular target system. The OS X command is ssh-keygen -t dsa or similar, then you copy and configure the public key on the target system. Here's an older discussion.

Add Password to Shell Script for ssh

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.