Advertisement
howtophil

monitor.sh

Mar 5th, 2024 (edited)
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.86 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. #---------------------------------
  4. # This is a sister-script for the
  5. # scanner-record.sh script.
  6. # https://pastebin.com/8vygm3wM
  7. # It will watch for new recordings
  8. # and by default beep then play
  9. # the recording.
  10. # You can change that to make it
  11. # email the recordings to you,
  12. # upload them someplace else,
  13. # or whatever else you want to do.
  14. #---------------------------------
  15. # Phillip J Rhoades (HowToPhil)
  16. # 2023-03-05
  17. #---------------------------------
  18.  
  19. #---------------------------------
  20. # Define variable(s) to control
  21. # how script functions
  22. #---------------------------------
  23. THEDIR="./record"
  24.  
  25. #---------------------------------
  26. # Time for the script to start
  27. # doing things!
  28. #---------------------------------
  29. echo "Begin monitoring the folder for new recordings!"
  30.  
  31. #---------------------------------
  32. # Wait for a new file to appear
  33. # in the directory.
  34. #---------------------------------
  35. inotifywait -q -m -r -e create --format '%w%f' "${THEDIR}" | while read THEFILE
  36. do
  37.     #---------------------------------
  38.     # Do this when a file is created
  39.     #---------------------------------
  40.     # Wait for the file to close so
  41.     # we can play it, move it, email
  42.     # it, or do whatever else we
  43.     # want.
  44.     #---------------------------------
  45.     inotifywait -q -e close_write "$THEFILE"
  46.     echo "New recording: $THEFILE"
  47.  
  48.     #---------------------------------
  49.     # This will beep at us, in case
  50.     # we don't want the file to play
  51.     # but we want to know a file has
  52.     # been created or we want a tone
  53.     # to get oru attention before the
  54.     # recording plays.
  55.     #---------------------------------
  56.     play -V1 -n -c1 synth .3 sine 200
  57.     #---------------------------------
  58.     # Play the file so we can hear
  59.     # what just came into the scanner.
  60.     #--------------------------------- 
  61.     play "$THEFILE"
  62.     echo
  63.     echo "->Monitoring the folder for the next new recording!"
  64. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement