#!/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