def run_remote(args):
    """Run a script on the frontend node inside a screen session."""
    config = common.ecluster_config(args.econfig)
    cluster = config.load_cluster(args.cluster)

    frontend = cluster.get_frontend_node()
    client = frontend.connect(known_hosts_file=cluster.known_hosts_file)

    cmd = "echo $HOME"
    stdin, stdout, stderr = client.exec_command(cmd)
    remote_home = stdout.read().strip()
    remote_file = os.path.join(remote_home, os.path.basename(args.script))
    log_file = "%s.log" % os.path.splitext(remote_file)[0]
    screen_name = os.path.splitext(os.path.basename(remote_file))[0]

    sftp = client.open_sftp()
    sftp.put(args.script, remote_file)
    sftp.close()

    cmd = "chmod a+x %s" % remote_file
    client.exec_command(cmd)
    cmd = "screen -d -m -S {} bash -c '{} &> {}'".format(
        screen_name, remote_file, log_file)
    stdin, stdout, stderr = client.exec_command(cmd)
    stdout.read()
    client.close()
    print("Running {} on AWS in screen session {}".format(
        remote_file, screen_name))
dataset/ETHPy150Open chapmanb/bcbio-nextgen-vm/bcbiovm/aws/cluster.py/run_remote/original