Created
April 10, 2015 15:48
-
-
Save xlcommunity/7f5faa53d7dbfecd3bbb to your computer and use it in GitHub Desktop.
RemoteScript.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS | |
# FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS. | |
from __future__ import with_statement | |
from overtherepy import OverthereHostSession, SshConnectionOptions, OverthereHost, StringUtils | |
import sys | |
host = OverthereHost(SshConnectionOptions(hostAddress, username, privateKey=privateKey)) | |
#logging must be turned of for use in XLR | |
session = OverthereHostSession(host, enable_logging=False) | |
with session: | |
remote_script = session.upload_text_content_to_work_dir(script, "script%s" % session.os.scriptExtension, executable=True) | |
response = session.execute([remote_script.path], check_success=False) | |
output = StringUtils.concat(response.stdout) | |
err = StringUtils.concat(response.stderr) | |
if response.rc == 0: | |
print output | |
else: | |
print "Exit code " | |
print response.rc | |
print "#### Output:" | |
print output | |
print "#### Error stream:" | |
print err | |
print "----" | |
sys.exit(response.rc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment