Skip to content

Instantly share code, notes, and snippets.

@kaspermunch
Created March 27, 2025 19:15
Show Gist options
  • Select an option

  • Save kaspermunch/7ad2f01ff791c84bbc1a28fae3a6c99f to your computer and use it in GitHub Desktop.

Select an option

Save kaspermunch/7ad2f01ff791c84bbc1a28fae3a6c99f to your computer and use it in GitHub Desktop.
gdk-code
#!/usr/bin/env bash
usage=$(cat <<-END
Use like this:
gdk-code -m <memory> -t <walltime> -a <account> ~/some/dir/on/genomedk
The following needs to be part of your .ssh/config file:
Host gdk
HostName login.genome.au.dk
User your_user_name_on_genomedk
Host cn-* gn-* s21n* s22n*
HostName %h
ProxyJump gdk
User your_user_name_on_genomedk
END
)
while getopts ":m:t:a:k:j" opt; do
case $opt in
k) jobname="$OPTARG"
ssh gdk "scancel --name=wrap"
exit 0;;
j) ssh gdk 'sacct -X --state=PENDING,RUNNING --format="jobid,jobname%30,partition,ReqMem,ReqCPUS,time,elapsed,state"'
exit 0;;
m) mem="$OPTARG"
;;
t) walltime="$OPTARG"
;;
a) account="$OPTARG"
;;
h) usage
exit 0;;
*) usage
exit 1;;
esac
done
shift $((OPTIND - 1))
open_dir=$1
if [ -z "$mem" ]; then mem="8g"; fi
if [ -z "$walltime" ]; then walltime="08:00:00"; fi
if [ "$1" = "-h" ] || [ -z "$1" ]; then
echo "$USAGE"
exit
fi
if [ "$HOSTNAME" = "fe-ipsych-01" ]; then
jobid=$(sbatch --mem-per-cpu=${mem} --cores=1 --time=${walltime} --account=${account} --wrap='sleep 6d' | awk '{print $4}')
echo "Submitted job with id: ${jobid}"
while [ -z "${is_running}" ]; do
sleep 5
is_running=$(jobinfo ${jobid} | grep RUNNING)
done
node=$(jobinfo $jobid | grep Nodes | awk '{print $3}')
echo "Job allocated core on node ${node}"
# conda run -n $environment ~/ChrXh2/VSCode-linux-x64/bin/code --folder-uri "vscode-remote://ssh-remote+${node}${open_dir}"
conda run -n $environment code --folder-uri "vscode-remote://ssh-remote+${node}${open_dir}"
else
jobid=$(ssh gdk "sbatch --mem-per-cpu=${mem} --cores=1 --time=${walltime} --account=${account} --wrap='sleep 6d'" | awk '{print $4}')
echo "Submitted job with id: ${jobid}"
while [ -z "${is_running}" ]; do
sleep 5
is_running=$(ssh gdk "jobinfo ${jobid}" | grep RUNNING)
done
node=$(ssh gdk "jobinfo $jobid" | grep Nodes | awk '{print $3}')
echo "Job allocated core on node ${node}"
code --folder-uri "vscode-remote://ssh-remote+${node}${open_dir}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment