inotify
inotify
Inotify bindings for Crystal language.
Installation
Add this to your application's shard.yml
:
dependencies:
inotify:
github: xtokio/inotify
Usage
require "inotify"
module WatchFiles
VERSION = "0.1.0"
# To watch a file or directory ...
puts "Monitor starts..."
recursive_monitor = true
watcher = Inotify.watch "/home/xtokio/monitor", recursive_monitor do |event|
# your logic
puts event.type
puts event.name
# rsync files
stdout = IO::Memory.new
stderr = IO::Memory.new
# Server (Connection with server is setup with ssh keys)
command = "rsync -r /home/xtokio/monitor/ root@64.227.6.48:/root/backup/"
exit_code = Process.run(command, shell:true, output:stdout, error:stderr)
# Local
command = "rsync -r /home/xtokio/monitor/ /home/xtokio/backup/"
exit_code = Process.run(command, shell:true, output:stdout, error:stderr)
puts exit_code
puts stdout
puts stderr
end
sleep 300
watcher.close
end
Note: You have to run something in the main fiber or else your program will exit.
Development
To enable logging to STDOUT
using environment variables, follow the instructions in the api docs. Use log source inotify
and severity level DEBUG
.
Contributing
- Fork it!
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- petoem Michael Petö - creator, maintainer
Repository
inotify
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- over 1 year ago
- July 16, 2023
License
MIT License
Links
Synced at
Fri, 22 Nov 2024 16:14:23 GMT
Languages