#!/bin/bash

# bl_run_hpc.sh - run a command remotely on the one of the ccxx compute nodes.
# Command will run in the current working directory.

# THIS SCRIPT ASSUMES THAT YOU HAVE ALREADY SETUP PASSWORDLESS LOGIN TO THE 
# REMOTE SYSTEM.

# This script as written is specific for the University of Manitoba CCL Linux cluster.
# You would need to modify it to run jobs remotely on your system.

# sshcc runs a job on a compute server, which mounts $HOME directories by NFS.
# Thus, in this case, the user's current working directory is the same on the source
# machine and on the compute server.
# GenBank is also on the NFS file server.

# On the CCL system, the sshcc command automatically chooses one of about a dozen
# compute nodes, so we have to call hostname to figure out which server, and then 
# tell the user in a pop up, so that they know where their job is running.

CDR=$PWD
#JOBID=$$

#----- This section taken from the IST script sshcc ------
# Connect to IST CC Compute node (Least Load)
source clustool
cluster='compute'
SRV=`cluster_load_top $cluster`
#----------------------------------------------------------

# Tried many many variations of this but because OkayBox2 requires quoted text, we can't have 
# quotes within quotes. 
#exec ssh $SRV "(hostname > host.$JOBID; java -jar $BIRCH/script/OkayBox2.jar 'Click to begin search on '`cat host.$JOBID`; cd $CDR; $*; hostname > host.$JOBID)"

#The solution is to run OkayBox in a separate script, bl_run_hpc_hostname.sh.
# The script finds the hostname and then calls OkayBox.
exec ssh $SRV "(bl_run_hpc_hostname.sh; cd $CDR; $*)"


