Print Files on Linux Remotely using Dropbox

If you have a printer attached to a Linux machine, you can easily send print jobs to that printer from another remote computer using Dropbox (see similar solutions for Windows and Mac).

The idea is that you create a shell script to monitor a local Dropbox folder. As soon as a new file is added to that folder from a remote computer (or mobile phone), the script will send the file to the attached printer. Once the the printing job is completed, the file is removed from the incoming queue.

The implementation is easy. Kurt Granroth sent me this improved shell script that you can use in any Linux environment. You only have to setup a cron job against this script such that it runs after every ‘n’ seconds (or minutes).

#!/bin/bash

export PrintQueue="/root/Dropbox/PrintQueue";

IFS=$'\n'

for PrintFile in $(/bin/ls -1 ${PrintQueue})

do
    lpr -r ${PrintQueue}/${PrintFile};
done

To initiate a print job, simply add some files to the PrintQueue Folder in Dropbox from either a remote computer or upload them via your mobile phone. Within seconds, the script will start printing the files to your local printer.

If you have multiple printers attached to Linux computer, use the – p parameter to specify the printer name.

Also, if you are on Ubuntu, you may use “sudo apt-get install gnome-schedule” (Gnome Schedule) to setup a scheduled task for the script with recurrence set to “every minute.”

Dropbox Printing with Linux Decoded

Here’s an annotated version of the script, courtesy Kurt again, that will help you easily understand how the script works:

#!/bin/bash — Specific bash directly since its feature set and behaviors are consistent everywhere

export PrintQueue — It’s necessary to ‘export’ in order for the environment variable to show up in the later $() subshell

IFS=$'\n' — By default, spaces will wreak havoc with the ‘for / in’ loop. Resetting the field separator handily works around that

/bin/ls -1 — Directly use /bin/ls to bypass the common color-enabling aliases. Use -1 to force all files into one column. There’s no need to search for the beginning of the file name using this

lpr -r — The -r option deletes the file after it successfully prints. This is better than doing an ‘rm’ later since it only does the delete on a successful print.

Amit Agarwal

Amit Agarwal

Google Developer Expert, Google Cloud Champion

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.

Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Awards & Titles

Digital Inspiration has won several awards since it's launch in 2004.

Google Developer Expert

Google Developer Expert

Google awarded us the Google Developer Expert award recogizing our work in Google Workspace.

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards in 2017.

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional (MVP) title for 5 years in a row.

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator title recognizing our technical skill and expertise.

Email Newsletter

Sign up for our email newsletter to stay up to date.

We will never send any spam emails. Promise.