Print Files on Linux Remotely using Dropbox

Published in: Dropbox - Linux - Print

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).


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


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

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

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.

📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Dropbox - Linux - Print

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

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. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube