From 6d1a2e9759325c8fe9aaf4bf41efdf44aa7aa5ef Mon Sep 17 00:00:00 2001 From: "Kasper D. Fischer" Date: Fri, 28 Jan 2022 16:30:39 +0100 Subject: [PATCH] Add example periodic_sleeper.sh This can be used as an template to create jobs which run periodically. Users should use this instead of cronjobs on the servers. --- examples/jobs/periodic_sleeper.sh | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 examples/jobs/periodic_sleeper.sh diff --git a/examples/jobs/periodic_sleeper.sh b/examples/jobs/periodic_sleeper.sh new file mode 100755 index 0000000..3a86e1c --- /dev/null +++ b/examples/jobs/periodic_sleeper.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# This job script takes a nap for 10 seconds (or paramter $2) every 30 minutes (or paramter $1) + +# SGE options +#$ -N PSleeper +#$ -l scf=1M,mem=100M,h_vmem=100M +#$ -q normal.q +#$ -cwd + +# process args +case "$1" in + -h) + echo "usage: $0 [-h | [-d] [T] [nap]]" + echo "periodically take a nap" + echo "" + echo "-h print this help and exit" + echo "-d print debug info" + echo "T take a nap every T minutes (default: 30)" + echo "nap take a nap for nap seconds (default: 10)" + exit 1 + ;; + *) + debug=0 + terse="-terse" + debug_flag="" + do_echo=0 + T=30 + nap=10 + while (( "$#" )); do + case "$1" in + -d) + debug=1 + terse="" + debug_flag="-d" + do_echo=1 + ;; + *) + T=${1:-30} + nap=${2:-10} + break + ;; + esac + shift + done + ;; +esac + +# set other variables +next=$(date -d "${T} minutes" +%Y%m%d%H%M) +script=/opt/SGE/examples/jobs/periodic_sleeper.sh + +# output some informations +if [ ${debug} -eq 1 ]; then + echo "T = ${T}, nap=${nap}" + echo "next run at ${next} (YYYYMMDDhhmm)" + echo "debug_flag = ${debug_flag}, do_echo = ${do_echo}" + echo "" +fi + +# commands to run in Grid Engine +/opt/SGE/examples/jobs/sleeper.sh ${nap} ${do_echo} + +# re-submit script to execute in T minutes +jobid=$(qsub ${terse} -a ${next} ${script} ${debug_flag} ${T} ${nap}) +exit_code=$? +if [ ${debug} -eq 1 ]; then + echo "${jobid}" +fi +if [ ${exit_code} -ne 0 ]; then + if [ ${debug} -eq 1 ]; then + echo "${jobid}" + echo "Ups, something went wrong, check output!" + fi + exit ${exit_code} +fi