elphel-ssh.bbclass 626 Bytes
Newer Older
1
# Need this function in another recipe
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
2 3 4 5 6 7 8 9 10

def command_over_ssh(d,command):
    import subprocess
    user = d.getVar('REMOTE_USER', True)
    id = d.getVar('IDENTITY_FILE', True)
    ip = d.getVar('REMOTE_IP', True)
    cmd = "ssh -i "+id+" "+user+"@"+ip+" "+command
    print("cmd: "+cmd)
    try:
11 12 13
        ret = subprocess.run(cmd,stderr=subprocess.STDOUT,shell=True)
    except subprocess.CalledProcessError as e:
        print("Error code: "+e.returncode)
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
14
        raise Exception("Copying to target requires access by public key. Run: \033[1;37mssh-copy-id "+REMOTE_USER+"@"+REMOTE_IP+"\033[0m")
15 16

    return str(ret).strip()