crontabで10秒おきに処理を実行するためのスクリプト雛形

単純に処理を実行して10秒スリープを6回繰り返す感じです

#!/bin/sh
source /root/.bash_profile
START=`date "+%s"`
LOCK_FILE=subcron.lock
CURRENT_LOCK=${LOCK_FILE}`date "+%Y%m%d%H"`

for i in {0..6};
do
  CURRENT=`date "+%s"`;
  SECONDS=`expr ${CURRENT} - ${START}`;

  if [ ! -e /tmp/${CURRENT_LOCK} ]; then
    if [ ${SECONDS} -lt 60 ]; then
      touch /tmp/${CURRENT_LOCK}

      echo "Do Something"
      
      rm -fr /tmp/${LOCK_FILE}*
    else
      echo "Timeout at ${i}";
      exit 0;
    fi
  else
    echo "Lock File /tmp/${CURRENT_LOCK} exists."
  fi


  NEXT_COUNT=`expr ${i} + 1`;
  NEXT=`expr ${NEXT_COUNT} * 10`;
  if [ ${NEXT} -gt ${SECONDS} ]; then
    sleep `expr ${NEXT} - ${SECONDS}`;
  else
    DELAY="`expr ${SECONDS} - ${NEXT}`"
    echo "Delayed for ${DELAY} seconds"
  fi
done;