Commit e4b9bd0f authored by Gaute Hope's avatar Gaute Hope

Added example surerun script

Added example surerun script that checks if a command has been run the
since midnight, otherwise run and updated timestamp.
parent ff00ce93
#! /bin/bash
# Copyright Gaute Hope <eg@gaute.vetsj.com> (c) 2010
# This script is released under the GNU General Public Licence v2
# Checks if a task has been run since midnight; otherwisely run it
# and update timestamp.
# State is saved in ~/.surerun; use at own risk and modify for your use
# usage: ./surerun title command *args
if [ $# -lt 2 ]; then
echo "Not enough arguments given"
exit 1
fi
title=$1
shift
command=$@
statedir=~/.surerun
midnight=$(date -d "00:00" +%s)
if [ -e "${statedir}/${title}" ]; then
# exists, check last run
lastrun=$(cat "${statedir}/${title}")
echo "Last run: ${lastrun}"
else
lastrun=0
fi
if [ "${lastrun}" -le "${midnight}" ]; then
if [ ! -d "${statedir}" ]; then
mkdir -p "${statedir}"
fi
date +%s > "${statedir}/${title}"
# run task
echo "Running: ${title}.."
$@
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment