watcher-script-ohne-watch.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # Klimbim Software collection, A bag full of things
  3. # Copyright (C) 2011-2023 Johannes 'Banana' Keßler
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. # 2016 http://www.bananas-playground.net
  18. # create a loop which checks for file modifications.
  19. # If so start a process
  20. # this loop waits 10 seconds and checks if there are files modified in the past 10 seconds.
  21. # color the output
  22. cecho () {
  23. local red='\033[0;31m'
  24. local blue='\033[0;34m'
  25. local green='\033[0;32m'
  26. local cyan='\033[0;36m'
  27. local purple='\033[0;35m'
  28. local brown='\033[0;33m'
  29. local yellow='\033[1;33m'
  30. local white='\033[1;37m'
  31. local black='\033[0;30m'
  32. local message=$1
  33. local color=${!2-$white}
  34. echo -en "$color"
  35. echo "$message"
  36. echo -en "\033[0m" # reset color
  37. return
  38. }
  39. target=/path/to/dir;
  40. found=;
  41. if [ -z $target ] ; then
  42. cecho "Missing target" red;
  43. exit 1;
  44. fi
  45. if [ -d "$target" ]; then
  46. while :
  47. do
  48. found=`find $target -mtime -10s -type f`
  49. if [ ! -z "$found" ] ; then
  50. cecho "do some'";
  51. fi
  52. sleep 10
  53. done
  54. fi