in awscli/customizations/opsworks.py [0:0]
def ssh(self, args, remote_script):
"""
Runs a (sh) script on a remote machine via SSH.
"""
if platform.system() == 'Windows':
try:
script_file = tempfile.NamedTemporaryFile("wt", delete=False)
script_file.write(remote_script)
script_file.close()
if args.ssh:
call = args.ssh
else:
call = 'plink'
if args.username:
call += ' -l "%s"' % args.username
if args.private_key:
call += ' -i "%s"' % args.private_key
call += ' "%s"' % self._use_address
call += ' -m'
call += ' "%s"' % script_file.name
subprocess.check_call(call, shell=True)
finally:
os.remove(script_file.name)
else:
if args.ssh:
call = shlex.split(str(args.ssh))
else:
call = ['ssh', '-tt']
if args.username:
call.extend(['-l', args.username])
if args.private_key:
call.extend(['-i', args.private_key])
call.append(self._use_address)
remote_call = ["/bin/sh", "-c", remote_script]
call.append(" ".join(shlex.quote(word) for word in remote_call))
subprocess.check_call(call)