Remote printing at home via DropBox

This entry was posted by Sunday, 26 June, 2011
Read the rest of this entry »

So, i want to often print things, however rarely am i at home to print, and by the time i get there i forget entirely about it. This is something i did one sunday evening to get printing on pretty much every device in the house to my home printer, at home or at work, or even on the road!

First of all, i setup myself a dropbox account (which is free). This is a file sharing ‘cloud’ style service which is fairly well known and popular.
I installed dropbox on my phone, my iPod touch, Work PC, Home Laptops or other computers and pretty much everything that supported it.

I used these Step by Step instructions to set it up on my gateway (which also has the printer attached) via a command line interface http://wiki.dropbox.com/TipsAndTricks/TextBasedLinuxInstall#Step-by-stepversion.

Once i had it mounted on the gateway/printing box, i ran the following commands

cd ~/Dropbox/
mkdir printer
cd printer
mkdir new done

This gives me a directory structure to work with for printing. The idea was to have a script poll the ‘new’ directory, and anything in there got sent to the printer, then moved to the ‘done’ directory. Should it not print correctly i can grab it from the done dir and retry later on.
I wrote a script named ‘script.sh’ and looked like this

#!/bin/bash
for file in `ls /home/velofille/Dropbox/printer/new/`
do lp -d laser /home/velofille/Dropbox/printer/new/$file  | mail -s "Print Job"  liz@mydomain.com
mv /home/velofille/Dropbox/printer/new/$file /home/velofille/Dropbox/printer/done/
done
chmod +x script.sh

I ran a few tests to make sure this worked ok, and sorted out a few printer driver errors. Once i had that working nicely, i added the pipe to my email address so i could confirm it printed (and any errors), then setup a crontab
*/5 * * * * /home/velofille/Dropbox/printer/script.sh >/dev/null 2>&1

That’s pretty much it in a nutshell, not overly complex or hard, the main thing will be making sure the Dropbox stays up and going.
To do this, i have the following shell script called checkdropbox.sh

#!/bin/sh
SERVICE='/home/velofille/.dropbox-dist/dropbox'
 
if ! ps ax | grep -v grep | grep $SERVICE > /dev/null
then
    /home/velofille/.dropbox-dist/dropbox &
    echo "$SERVICE is not running! Had to restart it" | mail -s "$SERVICE down" liz@mydomain.com
fi
chmod +x checkdropbox.sh

I then also put another crontab exactly the same as the printer one to run this

*/5 * * * * /home/velofille/bin/checkdropbox.sh >/dev/null 2>&1

Now i can print from pretty much anywhere in the world by simply dropping a file into a dropbox directory , then have an emailed report when that printed!


Leave a Reply