Guest User

Untitled

a guest
Nov 7th, 2025
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.14 KB | None | 0 0
  1.  
  2. #!/usr/bin/env bash
  3.  
  4. source "$HOME/klipper-backup/.env"
  5. watchlist=""
  6. for path in "${backupPaths[@]}"; do
  7.     for file in $path; do
  8.         if [ ! -h "$file" ]; then
  9.             file_dir=$(dirname "$file")
  10.             if [ "$file_dir" = "." ]; then
  11.                 watchlist+=" $HOME/$file"
  12.             else
  13.                 watchlist+=" $HOME/$file_dir"
  14.             fi
  15.         fi
  16.     done
  17. done
  18.  
  19. watchlist=$(echo "$watchlist" | tr ' ' '\n' | sort -u | tr '\n' ' ')
  20.  
  21. exclude_pattern=".swp|.tmp|printer-[0-9]*_[0-9]*.cfg|.bak|.bkp"
  22.  
  23. inotifywait -mrP -e close_write -e move -e delete --exclude "$exclude_pattern" $watchlist |
  24. while read -r path event file; do
  25.     if [ -z "$file" ]; then
  26.         file=$(basename "$path")
  27.     fi
  28.  
  29.     status=$(curl -s http://localhost:7125/printer/objects/query?print_stats | jq -r '.result.status.print_stats.state // empty')
  30.     if [ "$status" != "printing" ]; then
  31.         echo "Event Type: $event, Watched Path: $path, File Name: $file"
  32.         file="$file" /usr/bin/env bash -c "/usr/bin/env bash $HOME/klipper-backup/script.sh -c \"\$file modified - \$(date +'%x - %X')\"" > /dev/null 2>&1
  33.     fi
  34. done
  35.  
Advertisement
Add Comment
Please, Sign In to add comment