AppleScript für SSH-Befehl

macOSSSH

Hier ein AppleScript, mit dem ein SSH-Verbindung aufgebaut und anschließend ein SSH-Befehl ausgeführt werden kann:

set sshUser to "ssh-Benutzer"
set sshPasswd to "ssh-Passwort"
set sshServer to "ssh-Server"
set externalCommand to "ssh-Befehl"
set thecommand to "(echo \"spawn ssh"
set thecommand to thecommand & " " & sshUser & "@" & sshServer
set thecommand to thecommand & " " & externalCommand & "\" ;"
set thecommand to thecommand & "echo \"expect {\" ;"
set thecommand to thecommand & "echo \"\\\"password:\\\" {send \\\""
set thecommand to thecommand & sshPasswd
set thecommand to thecommand & "\\\\r\\\" ; exp_continue }\" ;"
set thecommand to thecommand & "echo \"\\\"yes/no?\\\" {send \\\"yes\\\\r\\\" ; exp_continue }\" ;"
set thecommand to thecommand & "echo \"eof\" ;"
set thecommand to thecommand & "echo \"}\" ;"
set thecommand to thecommand & ") | expect"
do shell script thecommand

Beispiel:
Über folgendes Script wird über eine SSH-Verbindung der Befehl für das Update der RSS-Feeds von Tiny Tiny RSS (TTRSS) ausgeführt.

set sshUser to "linkemarco.de"
set sshPasswd to "PaSsWoRt"
set sshServer to "ssh.strato.de"
set externalCommand to "/home/strato/http/premium/rid/04/83/54370483/htdocs/lm_ttrss/update.php --feeds --quiet"
set thecommand to "(echo \"spawn ssh"
set thecommand to thecommand & " " & sshUser & "@" & sshServer
set thecommand to thecommand & " " & externalCommand & "\" ;"
set thecommand to thecommand & "echo \"expect {\" ;"
set thecommand to thecommand & "echo \"\\\"password:\\\" {send \\\""
set thecommand to thecommand & sshPasswd
set thecommand to thecommand & "\\\\r\\\" ; exp_continue }\" ;"
set thecommand to thecommand & "echo \"\\\"yes/no?\\\" {send \\\"yes\\\\r\\\" ; exp_continue }\" ;"
set thecommand to thecommand & "echo \"eof\" ;"
set thecommand to thecommand & "echo \"}\" ;"
set thecommand to thecommand & ") | expect"
do shell script thecommand