#!/bin/bash if [[ $- == *i* ]] then echo this bash is interactive fi # Function to perform cleanup cleanup() { rm -f "$temp_stderr" } # Set up trap to call cleanup function on exit trap cleanup EXIT # Check if a configuration file argument was provided if [ $# -ne 1 ]; then echo "Usage: $0 " exit 1 fi # Strip the ".yaml" extension from the configuration file argument config_name=$(basename "$1" .yaml) config_file="/etc/borgmatic.d/$1" # Check if the configuration file exists if [ ! -f "$config_file" ]; then echo "Configuration file '$config_file' does not exist. Exiting." exit 1 fi # Path to the virtual environment's activate script activate_script="/opt/borg-env/bin/activate" # Check if the activate script exists if [ ! -f "$activate_script" ]; then echo "Virtual environment activate script '$activate_script' does not exist. Exiting." exit 1 fi # Activate the virtual environment source "$activate_script" #temp_stderr=$(mktemp) borgmatic --no-color --verbosity -2 --syslog-verbosity 1 --list --stats -c "$config_file" > /dev/null # 2> "$temp_stderr" | { # while IFS= read -r line; do # echo "$line" | logger -t bm-stdout-$config_name # done # } # # Read the temporary stderr log file and send its contents to journald using systemd-cat # cat "$temp_stderr" | while IFS= read -r line; do # echo "$line" | logger -t bm-stderr-$config_name # done # # Clean up the temporary log files # rm "$temp_stderr"