Skip to content

Commit 8c5a929

Browse files
committed
Added a sample polling script.
1 parent 56587e4 commit 8c5a929

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dbox
33

44
An easy way to push and pull your Dropbox folders, with fine-grained control over what folder you are syncing, where you are syncing it to, and when you are doing it.
55

6-
**IMPORTANT:** This is **not** an automated Dropbox client. It will exit after sucessfully pushing/pulling, so if you want regular updates, you can run it in cron, a loop, etc.
6+
**IMPORTANT:** This is **not** an automated Dropbox client. It will exit after sucessfully pushing/pulling, so if you want regular updates, you can run it in cron, a loop, etc. If you do want to run it in a loop, take a look at [sample_polling_script.rb](http://github.com/kenpratt/dbox/blob/master/sample_poll_script.rb).
77

88

99
Installation

sample_polling_script.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env ruby
2+
3+
require "rubygems"
4+
require "dbox"
5+
6+
ENV["DROPBOX_APP_KEY"] = "cmlrrjd3j0gbend"
7+
ENV["DROPBOX_APP_SECRET"] = "uvuulp75xf9jffl"
8+
ENV["DROPBOX_AUTH_KEY"] = "v4d7l1rez1czksn"
9+
ENV["DROPBOX_AUTH_SECRET"] = "pqej9rmnj0i1gcxr4"
10+
11+
LOGFILE = "/home/myuser/dbox.log"
12+
LOCAL_PATH = "/home/myuser/dropbox"
13+
REMOTE_PATH = "/stuff/myfolder"
14+
INTERVAL = 60 # time between syncs, in seconds
15+
16+
LOGGER = Logger.new(LOGFILE, 1, 1024000)
17+
LOGGER.level = Logger::INFO
18+
19+
def main
20+
while 1
21+
begin
22+
sync
23+
rescue Interrupt => e
24+
exit 0
25+
rescue Exception => e
26+
LOGGER.error e
27+
end
28+
sleep INTERVAL
29+
end
30+
end
31+
32+
def sync
33+
unless Dbox.exists?(LOCAL_PATH)
34+
LOGGER.info "Cloning"
35+
Dbox.clone(REMOTE_PATH, LOCAL_PATH)
36+
LOGGER.info "Done"
37+
else
38+
LOGGER.info "Syncing"
39+
Dbox.push(LOCAL_PATH)
40+
Dbox.pull(LOCAL_PATH)
41+
LOGGER.info "Done"
42+
end
43+
end
44+
45+
main

0 commit comments

Comments
 (0)