From 4fb56fea26d27a978eb62d7303631186317852e2 Mon Sep 17 00:00:00 2001 From: InigoGutierrez Date: Tue, 19 Jul 2022 11:05:08 +0000 Subject: Created data folder and store.sh, a script to store data in a server. --- data/.store.sh.swp | Bin 0 -> 12288 bytes data/README.md | 3 +++ data/store.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 data/.store.sh.swp create mode 100644 data/README.md create mode 100755 data/store.sh diff --git a/data/.store.sh.swp b/data/.store.sh.swp new file mode 100644 index 0000000..0d97b26 Binary files /dev/null and b/data/.store.sh.swp 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 -- cgit v1.2.1