Co-authored-by: jon brookes <marshyon@gmail.com> Reviewed-on: https://codeberg.org/headshed/share-lt/pulls/18
33 lines
No EOL
870 B
Bash
Executable file
33 lines
No EOL
870 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
LOG_FILE="/tmp/logfile.log"
|
|
|
|
# Redirect all output to both stdout and the log file
|
|
exec > >(tee -a "$LOG_FILE") 2>&1
|
|
|
|
# Read the first two command line arguments
|
|
ACTION=$1
|
|
FILENAME=$2
|
|
|
|
# Check if the file exists and echo its contents
|
|
if [[ -f "$FILENAME" ]]; then
|
|
echo "Contents of the file $FILENAME:"
|
|
cat "$FILENAME" | jq
|
|
else
|
|
echo "Error: File $FILENAME does not exist."
|
|
fi
|
|
|
|
echo
|
|
# Read and print command line arguments
|
|
echo "=============================="
|
|
echo "ACTION: $ACTION"
|
|
echo "FILENAME: $FILENAME"
|
|
echo "=============================="
|
|
echo
|
|
|
|
# Publish message and check return code
|
|
if nats pub $NATS_SUBJECT "$(cat "$FILENAME")" --server $NATS_URL --user $NATS_USERNAME --password $NATS_PASSWORD; then
|
|
echo "Success: Message published to NATS successfully."
|
|
else
|
|
echo "Error: Failed to publish message to NATS."
|
|
fi |