Compare commits

...

2 Commits

Author SHA1 Message Date
6d1a2e9759 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.
2022-01-28 16:30:39 +01:00
deaa1effd9 removed warning if qstat is not found
qstat can not be found on host with outdated debian versions. These hosts do not have GPU's installed.
2022-01-28 16:29:11 +01:00
2 changed files with 77 additions and 2 deletions

View File

@ -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

View File

@ -35,7 +35,7 @@ function clean_up() {
### get requested number of GPU's
# use hard resource list first
NGPUS=$(qstat -j ${JOB_ID} | sed -n "s/hard resource_list:.*gpu=\([[:digit:]]\+\).*/\1/p")
NGPUS=$(qstat -j ${JOB_ID} 2>/dev/null | sed -n "s/hard resource_list:.*gpu=\([[:digit:]]\+\).*/\1/p")
# set NGPUS to zero if empty
if [ -z "${NGPUS}" ] ; then
NGPUS=0
@ -68,4 +68,4 @@ else
fi
# clean exit
exit 0
exit 0