Exemplo n.º 1
0
def exec_command( step_name, shell_command, ssh, response, *args, **kwargs ):

    stdin, stdout, stderr = ssh.exec_command( shell_command )
    r = { 
	STEP_NAME	: '[ STEP %s ] : %s' % ( len( response.execution[ STEPS ] ) + 1, step_name ),
        RETURN_CODE   	: stdout.channel.recv_exit_status(),
        STDOUT		: [ line.rstrip( os.linesep ).decode( 'iso8859', 'replace' ) for line in stdout.readlines() ],
	STDERR		: [ line.rstrip( os.linesep ).decode( 'iso8859', 'replace' ) for line in stderr.readlines() ],
    }
    response.execution[ STEPS ].append( r )
    return r
Exemplo n.º 2
0
def linux():
	if request.method == 'POST':
		f =request.files['file']
		f.save(secure_filename(f.filename))
		# Connect the linux with ssh
		ssh = paramiko.SSHClient()
		# Load or generate the host key 
		ssh.load_system_host_keys()
		ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
		# Connect the server
		ssh.connect("58.206.100.172", port=2222, username="******", password="******")
		# stdin,stdout,stderr = ssh.exec_command('mkdir aliServer')

		with closing(scpclient.Write(ssh.get_transport(), remote_path="/home/keyyd/aliServer")) as scp:
			scp.send_file(f.filename, preserve_times=True)
		stdin, stdout, stderr = ssh.exec_command('python aliServer/main.py')
		return render_template('help.html', name=f.filename, data=stdout.read())
Exemplo n.º 3
0
def lambda_handler(event, context):
    # TODO implement
    logger.info(event)
    logger.info("After event")
    s3_client = boto3.client('s3')
    s3_client.download_file('thulasi-ram-dum', 'ec2andemr.pem', '/tmp/ec2.pem')
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    privkey = paramiko.RSAKey.from_private_key_file('/tmp/ec2.pem')
    #instance_id = "i-058481edd4788c01c"
    ssh.connect('ec2-18-221-144-29.us-east-2.compute.amazonaws.com',
                username='******',
                pkey=privkey)
    stdin, stdout, stderr = ssh.exec_command(
        'echo "ssh to ec2 instance successful"')
    data = stdout.read().splitlines()
    for line in data:
        print(line)
    return {"statusCode": 200, "body": json.dumps('Hello from Lambda!')}
Exemplo n.º 4
0
 def openSSHSession(self):
     #pass
     if self._sshSession is not None: return
     ssh = paramiko.SSHClient()
     ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
     ssh.connect(self.IP, username='******', password=self.Password, port=self.Port)
     ssh.exec_command('s')
     ssh.exec_command('l')
     ssh.exec_command('visonic')
     transport = ssh.get_transport()
     channel = transport.open_session()
     #
     self._sshSession = ssh
     self._sshChannel = channel
Exemplo n.º 5
0
import ssh
import paramiko
import datetime
import smtplib
ssh = paramiko.SSHClient()
hostname = "159.89.170.250"
username = ""
password = ""
command = "df -h"
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
x = ssh.connect(hostname, 22, username, password)
ssh.invoke_shell()
stdin, stdout, stderr = ssh.exec_command(command)
x = stdout.read()

text_file = open("Output.txt", "a")
datex = str(datetime.date.today())
text_file.write(datex)
text_file.write("\n")
timex = str(datetime.datetime.now().time())
text_file.write(timex)
text_file.write("\n")
text_file.write(x)
text_file.write("***********************\n")

text_file.close()

fromaddr = '*****@*****.**'
toaddrs = '*****@*****.**', '*****@*****.**', '*****@*****.**', '[email protected] '
msg = "\r\n".join([
    "To: [email protected]", "Subject: Today's Serever Health", "",
Exemplo n.º 6
0
#!/usr/bin/env python

from argparse import ArgumentParser
import ssh
import sys


if __name__ == '__main__':
    arg_parser = ArgumentParser(description='do ls on remote server')
    arg_parser.add_argument('--host', required=True,
                            help='host name to connect to')
    arg_parser.add_argument('--user', required=True,
                            help='user name to connect as')
    options = arg_parser.parse_args()
    ssh = ssh.connect(options.host, options.user)
    module_func_defs = '. /apps/leuven/etc/bash.bashrc'
    cmd = '{0}; module load accounting; gbalance'.format(module_func_defs)
    _, stdout, stderr = ssh.exec_command(cmd)
    for line in stdout:
        print(line.rstrip())
    for line in stderr:
        print(line.rstrip(), file=sys.stderr)
    ssh.close()
Exemplo n.º 7
0
#!/usr/bin/env python

from argparse import ArgumentParser
import ssh
import sys

if __name__ == '__main__':
    arg_parser = ArgumentParser(description='do ls on remote server')
    arg_parser.add_argument('--host',
                            required=True,
                            help='host name to connect to')
    arg_parser.add_argument('--user',
                            required=True,
                            help='user name to connect as')
    arg_parser.add_argument('module', help='module to query for')
    options = arg_parser.parse_args()
    ssh = ssh.connect(options.host, options.user)
    module_func_defs = '. /apps/leuven/etc/bash.bashrc; . switch_to_2015a'
    cmd = '{0}; module av {1}'.format(module_func_defs, options.module)
    _, stdout, stderr = ssh.exec_command(cmd)
    for line in stdout:
        print(line.rstrip())
    for line in stderr:
        print(line.rstrip(), file=sys.stderr)
    ssh.close()
Exemplo n.º 8
0
# coding:utf-8

import ssh

# 接続情報
HOST = '192.168.43.50'
USER = '******'
PASS = '******'
PORT = 22

# ssh接続
ssh = ssh.SSHClient()
ssh.load_system_host_keys()
ssh.connect(HOST, username=USER, password=PASS, port=PORT)

# コマンド実行
stdin, stdout, stderr = ssh.exec_command('ls -l')

# 実行結果出力
for line in stdout.read().split('\n'):
    print line

# 切断
ssh.close()
Exemplo n.º 9
0
#!/usr/bin/env python

from argparse import ArgumentParser
import ssh
import sys

if __name__ == '__main__':
    arg_parser = ArgumentParser(description='do ls on remote server')
    arg_parser.add_argument('--host',
                            required=True,
                            help='host name to connect to')
    arg_parser.add_argument('--user',
                            required=True,
                            help='user name to connect as')
    arg_parser.add_argument('module', help='module to query for')
    options = arg_parser.parse_args()
    ssh = ssh.connect(options.host, options.user)
    cmd = f'bash -l -c module av {options.module};'
    _, stdout, stderr = ssh.exec_command(cmd, get_pty=True)
    for line in stdout:
        print(line.rstrip())
    for line in stderr:
        print(line.rstrip(), file=sys.stderr)
    ssh.close()