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

     
  1: --- dropprint.sh ---     
2:     
3: #!/bin/bash     
4:     
5: export PrintQueue="/root/Dropbox/PrintQueue";     
6:     
7: IFS=$'\n'     
8:     
9: for PrintFile in $(/bin/ls -1 ${PrintQueue}) do     
10:     
11:    lpr -r ${PrintQueue}/${PrintFile};     
12:     
13: done     
14:     
15: --- dropprint.sh ---
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."
What the script does?
Here’s an annotated version of the script, courtesy Kurt again, that will help you easily understand how the script works:
1. #!/bin/bash
Specific bash directly since its feature set and behaviors are consistent everywhere
2. export PrintQueue
It’s necessary to ‘export’ in order for the environment variable to show up in the later $() subshell
3. IFS=$’\n’
By default, spaces will wreak havoc with the ‘for / in’ loop. Resetting the field separator handily works around that
4. /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
5. 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.

0 comments: