[gnome-schedule] Added example surerun script



commit e4b9bd0fd0af414d68975c25bb292a3f8cf95aa5
Author: Gaute Hope <eg gaute vetsj com>
Date:   Tue Sep 14 21:04:05 2010 +0200

    Added example surerun script
    
    Added example surerun script that checks if a command has been run the
    since midnight, otherwise run and updated timestamp.

 src/examples/surerun |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/src/examples/surerun b/src/examples/surerun
new file mode 100755
index 0000000..18f853e
--- /dev/null
+++ b/src/examples/surerun
@@ -0,0 +1,45 @@
+#! /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
+
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]