aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInigoGutierrez <taamas@taamas.xyz>2022-07-19 11:05:08 +0000
committerInigoGutierrez <taamas@taamas.xyz>2022-07-19 11:05:08 +0000
commit4fb56fea26d27a978eb62d7303631186317852e2 (patch)
treeeeb7a1433001300161b6e2380c0dab2479bb0e8e
parent916ec9ba2b112e32d9ed3ca2387cda57b14a7bb5 (diff)
downloadscripts-4fb56fea26d27a978eb62d7303631186317852e2.tar.gz
scripts-4fb56fea26d27a978eb62d7303631186317852e2.zip
Created data folder and store.sh, a script to store data in a server.
-rw-r--r--data/.store.sh.swpbin0 -> 12288 bytes
-rw-r--r--data/README.md3
-rwxr-xr-xdata/store.sh61
3 files changed, 64 insertions, 0 deletions
diff --git a/data/.store.sh.swp b/data/.store.sh.swp
new file mode 100644
index 0000000..0d97b26
--- /dev/null
+++ b/data/.store.sh.swp
Binary files differ
diff --git a/data/README.md b/data/README.md
new file mode 100644
index 0000000..1419ee0
--- /dev/null
+++ b/data/README.md
@@ -0,0 +1,3 @@
+# Data
+
+Scripts to record and show data.
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