How to Print Files on Linux Remotely Using Dropbox
We all know how simple it is to simplify
tasks using scripts in Linux, unlike in other Mac and Windows where the
software is closed source. In Linux we can do all sorts of stuff, like
in this instance, use it send print jobs from another remote computer.
If a
new file is added to that folder via a remote computer, or even a
mobile phone, the script will send the file to the attached printer.
Once the printing job is complete, the file will be removed from the folder.
Implementation
is easy. All you need is this shell script that you can use in any
Linux environment. You just need to setup a cron job for this script and
let it run every 'n' seconds or minutes.
To initiate the job,
simply add some files to the PrintQueue or whatever you name the folder
for remote printing in the Dropbox or upload it via your mobile phone
using the Dropbox app. You can also send the file via email using IFFT
app. Wait for a few seconds and the script will start instructing the
computer to print the files added in the folder
If you have multiple printers attached to the Linux computer, you can use the -p parameter to specify the printer name.
If
you are using Ubuntu, install Gnome Schedule to setup the scheduled
task with recurrence to either every second or every minute. To install
the app, simple open Ubuntu Software Center or use this command in the
terminal: sudo apt-get install gnome-schedule.
Here's the script
:#!/bin/bash
export PrintQueue="/root/Dropbox/PrintQueue";
IFS=$'\ '
for PrintFile in $(/bin/ls -1 ${PrintQueue})
do
lpr -r ${PrintQueue}/${PrintFile};
done
Remember if you use a different folder name for your remote printing replace "PrintQueue" with the one that you named
.
Decoding the script
Here's an annotation of the script to help you understand how it works:
#!/bin/bash
This is to instruct the computer that this is a bash file.
export PrintQueue
This is necessary in order for the variable to show up in the later $() subshell.
IFS=$'\n'
By default, spaces will wreck havoc in the 'for / in' loop, this will solve that.
/bin/ls -1
Use the /bin/ls to bypass common color-enabling aliases. Use -1 to force all files into one column.
lpr -r
This option deletes the file after it successfully prints.
Troubleshooting
Make
sure that the printer is connected to your Linux machine and is working
properly. Do a test print manually first before performing a remote
print.
The printer and your Linux computer should be turned on at
all times. Otherwise, the printing job will resume when both devices are
turned on.
This handles multiple files in one go and is expected to print almost all file formats.
0 comments: