Ejemplo n.º 1
0
def ssh_verify(name, i):

    server_info = data.servers[i]
    if ('port' in server_info):
        port = server_info['port']
    else:
        port = 22
    cmd = 'cd ;ls;'
    ssh = pexpect.spawn('ssh %s@%s  -p %s  "%s"' %
                        (server_info['user'], server_info['host'], port, cmd))
    msg = '\33[34m%d:\33[33m%s@%s(%s):\33[0m ' % (
        i, server_info['user'], server_info['name'],
        common.hideipFun(server_info['host']))

    try:
        status = ssh.expect(['password:'******'continue connecting (yes/no)?'],
                            timeout=20)
        if status == 0:
            ssh.sendline(server_info['password'])
            ssh.sendline(cmd)
            print(msg + ' \033[32mSuccess\033[0m')
        elif status == 1:
            ssh.sendline('yes\n')
            ssh.expect('password: '******'password'])
            ssh.sendline(cmd)
            print(msg + ' \033[32mAdd public key successfully\033[0m')
        ssh.close()
        return
    except pexpect.EOF:
        print(msg + ' \033[31mEOF\033[0m')
        ssh.close()
    except pexpect.TIMEOUT:
        print(msg + ' \033[31mTimeout\033[0m')
        ssh.close()
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
    else:
        cd_cmd = 'cd /code_path/'

    chan.send(cd_cmd + '\n')
    cmd_result(chan)

    chan.send('sudo ls -lh' + '\n')
    login_prompt(chan)
    # resp = chan.recv(100000)
    # print resp
    chan.send(password)
    chan.send('\n')
    cmd_result(chan)

    chan.send('sudo git pull' + '\n')
    git_pull_prompt_user(chan)
    chan.send(git_user + '\n')
    # chan.send('\n')
    git_pull_prompt_passwd(chan)
    chan.send(git_pass + '\n')
    print cmd_result(chan)

    chan.send('php server.php reload' + '\n')
    print cmd_result(chan)
    time.sleep(1)
    # chan.send('tail log/swoole.log'+'\n')
    # print cmd_result(chan)

    ssh.close()
    httpTest(host, location, count)
    count += 1