Dropbox using Command Line Interface

Overview

We love CLI don’t we. As Linux administrators we like to use command line interface as much as possible. This post is about using dropbox with CLI. The benefit of using dropbox is that its fast as you do not have to login to upload/backup something to dropbox file cloud.

Using dropbox using CLI

Lets download dropbox and start its daemon.


# cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
# wget http://linux.dropbox.com/packages/dropbox.py
# sudo mv dropbox.py /usr/local/bin/dropbox
# sudo chmod 755 /usr/local/bin/dropbox
# ~/.dropbox-dist/dropboxd &

At this point you may start getting the error messages “This client is not linked to any account”, telling you to register this machine with dropbox.

dropbox1 300x176 Dropbox using Command Line Interface

Just open the link provided by the message in a web browser and register the host. This is only a one time activity. Once done you will get a message “Client successfully linked”.

dropbox11 300x176 Dropbox using Command Line Interface

You will now see a directory named Dropbox. Any thing that you wish dropbox to backup/upload to cloud just put it in here.


# ls Dropbox
# dropbox lansync n
# dropbox autostart y

Lets create a startup script. Replace “keenan” with your linux account username on line 4. I found this script here.

# vi /etc/init.d/dropbox

#!/bin/sh
# dropbox service
# Replace with linux users you want to run Dropbox clients for
DROPBOX_USERS="keenan"
DAEMON=.dropbox-dist/dropbox
start() {
echo "Starting dropbox..."
for dbuser in $DROPBOX_USERS; do
HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
if [ -x $HOMEDIR/$DAEMON ]; then
HOME="$HOMEDIR" start-stop-daemon -b -o -c $dbuser -S -u $dbuser -x $HOMEDIR/$DAEMON
fi
done
}
stop() {
echo "Stopping dropbox..."
for dbuser in $DROPBOX_USERS; do
HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
if [ -x $HOMEDIR/$DAEMON ]; then
start-stop-daemon -o -c $dbuser -K -u $dbuser -x $HOMEDIR/$DAEMON
fi
done
}
status() {
for dbuser in $DROPBOX_USERS; do
dbpid=`pgrep -u $dbuser dropbox`
if [ -z $dbpid ] ; then
echo "dropboxd for USER $dbuser: not running."
else
echo "dropboxd for USER $dbuser: running (pid $dbpid)"
fi
done
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload|force-reload)
stop
start
;;
status)
status
;;
*)
echo "Usage: /etc/init.d/dropbox {start|stop|reload|force-reload|restart|status}"
exit 1
esac
exit 0

Make this script executable. And enter this in rc.local so it starts automatically when system boots.


# sudo chmod 755 /etc/init.d/dropbox
# sudo vi /etc/rc.local

Enter this line just above exit 0

/etc/init.d/dropbox start

Now lets upload/backup something to dropbox. I am creating a file here.


# touch newtest.docx

dropbox3 300x176 Dropbox using Command Line Interface

Now lets login to dropbox and see if it has our file.
dropbox4 300x110 Dropbox using Command Line Interface

Indeed it has. That is awesome!!!