Created
November 8, 2016 09:55
-
-
Save kossoff/b7e8df2937a00d456a5c4938442c7ae7 to your computer and use it in GitHub Desktop.
Service for watch Dropbox folder on linux & send notifications to Slack if new files added
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/home/RUBYUSER/.rvm/rubies/ruby-2.3.0/bin/ruby | |
require 'rubygems' | |
require 'rb-inotify' | |
require 'slack-notifier' | |
watcher = INotify::Notifier.new | |
notifier = Slack::Notifier.new "https://hooks.slack.com/services/SLACKWEBHOOKURL" | |
notifier.channel = '#CHANNEL_NAME' | |
watcher.watch("/home/RUBYUSER/Dropbox/", :create, :delete, :recursive) do |event| | |
event.flags.each do |flag| | |
flag = flag.to_s | |
case flag | |
when 'create' | |
if File.extname(event.name) == '.JPG' || File.extname(event.name) == '.JPEG' || File.extname(event.name) == '.jpg' || File.extname(event.name) == '.jpeg' | |
message = "New file http://SERVERNAME/#{event.absolute_name.sub( '/home/RUBYUSER/Dropbox/', '')}" | |
notifier.ping message | |
puts message | |
end | |
when 'delete' | |
puts "Deleted file #{event.absolute_name}" | |
else | |
end | |
end | |
end | |
## loop, wait for events from inotify | |
watcher.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment