commit 3ab34e4dd05aa673d04ee42cfb05b19a0a460ff2 Author: chris Date: Thu Mar 19 14:08:05 2026 +0100 Dateien nach "/" hochladen DE: Ein automatisiertes Skript, das mittels eines Linux-Cronjobs zyklisch ausgeführt wird, um Dateiinhalte zu lesen und diese an eine Custom Function zur weiteren Verarbeitung zu übermitteln. EN: An automated script triggered by a Linux cron job that periodically reads file contents and forwards them to a custom function for further processing. diff --git a/fileInterface.sh b/fileInterface.sh new file mode 100644 index 0000000..72b246a --- /dev/null +++ b/fileInterface.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +# Variablen +stationNumber="101010010" +url="http://localhost:8080" + +# Funktion, um den regLogin durchzuführen +performRegLogin() { + loginResponse=$(curl -v -X POST "$url/mes/imsapi/rest/actions/regLogin" \ + -H "Content-Type: application/json" \ + -d '{ + "sessionValidationStruct": { + "stationNumber": "'"$stationNumber"'", + "stationPassword": "", + "user": "", + "password": "", + "client": "01", + "registrationType": "S", + "systemIdentifier": "Shellscript" + } + }') + + echo "Login response: $loginResponse" # Zum Debuggen + + # Extrahieren der Session-Informationen + sessionId=$(echo "$loginResponse" | jq -r '.result.sessionContext.sessionId') + persId=$(echo "$loginResponse" | jq -r '.result.sessionContext.persId') + + echo "Session ID: $sessionId, Pers ID: $persId" # Zum Debuggen +} + + +# Funktion, um den Custom-Function-Aufruf durchzuführen +performCustomFunction() { + local file=$1 + # fileContent=$(sed 's/$/|/' "$file" | jq -Rs .) +fileContent=$(sed ':a;N;$!ba;s/\n/|/g' "$file" | jq -Rs .) +fileContent="${fileContent:1:-1}" # Entfernt das erste und letzte Zeichen + + echo "Session ID2: $sessionId, Pers ID: $persId" + echo "Filecontent: $fileContent" + + customFunctionResponse=$(curl -v --location "$url/mes/imsapi/rest/actions/customFunction" --header 'Accept: application/json' --header 'Content-Type: application/json' --data ' { + "sessionContext": { + "sessionId": "'$sessionId'", + "persId": "'$persId'", + "locale": "de" + }, + "methodName": "Fazit.EcuStringAudi", + "inArgs": [ "File_Response", "'"$fileContent"'", "ResponseLog", "receive", "Number", "NA", "0", "0" ] } ' + ) + +echo "CustomFunction Response: $customFunctionResponse" + returnValue=$(echo $customFunctionResponse | jq -r '.result.return_value') + mkdir -p ./error + mkdir -p ./done + if [[ "$returnValue" != "0" && "$returnValue" != "3" ]]; then + mv "$file" ./error/ + else + mv "$file" ./done/ + fi +} + + + + +regLogout() { + + + echo "Session ID2: $sessionId, Pers ID: $persId" + + + regLogout=$(curl -v --location "$url/mes/imsapi/rest/actions/regLogout" --header 'Accept: application/json' --header 'Content-Type: application/json' --data ' { + "sessionContext": { + "sessionId": "'$sessionId'", + "persId": "'$persId'", + "locale": "de"}}') + +echo "Reglogout Response: $regLogout" + +} + + +# Hauptlogik +# Verwenden von find anstelle von ls, um Dateien zu finden, die mindestens 5 Sekunden alt sind +# -mmin +0.083 entspricht ungefähr 5 Sekunden (5/60 Minuten) +xmlFiles=$(find . -maxdepth 1 -name "*.xml" -mmin +0.083 -type f 2>/dev/null) + +if [[ -n "$xmlFiles" ]]; then + performRegLogin + for file in $xmlFiles; do + # Entfernen des führenden './' aus dem Dateinamen + performCustomFunction "${file:2}" + done +regLogout +else + echo "Keine geeigneten XML-Dateien gefunden." +fi