diff options
-rwxr-xr-x | verwende | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/verwende b/verwende new file mode 100755 index 0000000..da7cb73 --- /dev/null +++ b/verwende @@ -0,0 +1,45 @@ +#!/bin/sh + +while read -r Barcode; do + [ -z "${Barcode}" ] && break + Barcode=$( + printf '%s' "${Barcode}" \ + | base64 -w0 + ) + infos=$( + for s in 'Schrauben' 'Muttern' 'Unterlegscheiben'; do + printf 'SELECT' + printf '"%s",`%s`.`id`' \ + "${s}" "${s}" + printf ' FROM `%s`' \ + "${s}" + printf ' WHERE `%s`.`Barcode`=FROM_BASE64("%s");\n' \ + "${s}" "${Barcode}" + done \ + | mysql -N --raw --batch \ + | tr '\t' ' ' + ) + if [ -z "${infos}" ]; then + >&2 echo 'Kann ich nicht finden.' + continue + fi + >&2 echo 'Wie viele entnommen?' + read diff + if ! { + printf 'UPDATE `%s`' \ + "${infos% *}" + printf ' SET `%s`.`Anzahl`=`%s`.`Anzahl`-%s' \ + "${infos% *}" \ + "${infos% *}" \ + "${diff}" + printf ' WHERE `%s`.`id`=%s;\n' \ + "${infos% *}" \ + "${infos#* }" + printf 'SELECT ROW_COUNT();\n' + } \ + | mysql -N --raw --batch \ + | grep -qxF '1'; then + >&2 echo 'mysql hat nicht genau eine Zeile geƤndert!' + exit 1 + fi +done |