aboutsummaryrefslogtreecommitdiff
path: root/data/store.sh
diff options
context:
space:
mode:
Diffstat (limited to 'data/store.sh')
-rwxr-xr-xdata/store.sh61
1 files changed, 61 insertions, 0 deletions
diff --git a/data/store.sh b/data/store.sh
new file mode 100755
index 0000000..d9c8b8f
--- /dev/null
+++ b/data/store.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+#
+# Apunta datos en el archivo correspondiente de un servidor.
+
+usageMessage='Usage: store.sh [-s SEPARATOR] [-S SERVER] -f FILE VALUE...\n'
+
+separator='#'
+server='taamas@taamas.xyz'
+file=''
+date=''
+time=''
+
+while echo "$1" | grep -q '^-'; do
+ case "$1" in
+
+ "-d")
+ [ -z "$2" ] && echo '-d option needs an argument.' >&2 && exit 1
+ date='true'
+ shift 1
+ ;;
+
+ "-f")
+ [ -z "$2" ] && echo '-f option needs an argument.' >&2 && exit 1
+ file="$2"
+ shift 2
+ ;;
+
+ "-s")
+ [ -z "$2" ] && echo '-s option needs an argument.' >&2 && exit 1
+ separator="$2"
+ shift 2
+ ;;
+
+ "-S")
+ [ -z "$2" ] && echo '-S option needs an argument.' >&2 && exit 1
+ server="$2"
+ shift 2
+ ;;
+
+ "-t")
+ [ -z "$2" ] && echo '-t option needs an argument.' >&2 && exit 1
+ time='true'
+ shift 1
+ ;;
+
+ esac
+done
+
+[ -z "$file" ] && printf "A remote file name must be provided with the -f flag.\n" >&2 && exit 2
+
+values="$@"
+[ -z "$values" ] && printf "$usageMessage" >&2 && exit 2
+formattedValues=''
+for value in "$@"; do
+ formattedValues="${formattedValues}${separator}${value}"
+done
+formattedValues="$(echo "$formattedValues" | sed "s/^${separator}//")"
+[ -n "$time" ] && formattedValues="$(date '+%H:%M:%S')${separator}${formattedValues}"
+[ -n "$date" ] && formattedValues="$(date '+%y/%m/%d')${separator}${formattedValues}"
+
+ssh "$server" "echo ${formattedValues} >>\"${file}\"" >/dev/null || exit 3