Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Submitting a job to a remote Grid Engine cluster using Paramiko (Python SSH client)
import tempfile
import os
import time
import paramiko
# Hostname of a 'submission host' in the Grid Engine cluster we want to submit a job to
hostname = ''
# Username for logging in to the cluster via SSH
username = "te1st"
# Path on the cluster where we will save our job submission script to
remote_qsub_script_path = os.path.join('/', 'home', username, "qsub_script_{}".format(int(time.time())))
# Job submission script
qsub_script = """#!/bin/bash
#$ -m bea
#$ -M
#$ -P rse
echo "Hello from $HOSTNAME"
# Save job submission script to a local temporary file
with tempfile.NamedTemporaryFile(mode='w', delete=False) as local_qsub_script_file:
with paramiko.SSHClient() as client:
# Establish SSH connection
client.connect(hostname, username=username)
# Establish SFTP connection
with client.open_sftp() as sftp:
# Push job submission script to a particular path on the cluster
sftp.put(, remote_qsub_script_path)
# Submit our Grid Engine job by running a remote 'qsub' command over SSH
stdin, stdout, stderr = client.exec_command("qsub {}".format(remote_qsub_script_path))
# Show the standard output and error of our job
print("Standard output:")
print("Standard error:")
print("Exit status: {}".format(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment