Friday 19 May 2017

Print Files on Linux Remotely using Dropbox



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.

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.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Labels

404 AdBlock Add-on Airtel GPRS Trick Airtel SMS Trick Alexa Amazon Amazon Kindle Amazon Prime Android Android 8 Android Oreo antivirus Apple Apple Mac ASCII Audacity Audio Authotkey Backup Balance Transfer in Vodafone Battery Bing Blogger Blogging Bookmarklet Browser Camera Chromebook clock Cloud colors command lines Computer Computer Tricks configuration Contact Creative Commons Credit Card CSS devolop DIY Doodle DOS Download Dropbox E-Mail eBook Email Email Attachment Embed Encryption English Error Evernote Eyes Facebook Facebook Tricks Feedburner Flipkart Font Foursquare Free Internet Free sms trick in Vodafone G Mail Gadget Game Getty Images GIF Gists Github Google Google AdSense Google Analytics Google Apps Google Chrome Google Contacts Google Currents Google DNS Google Docs Google Drive Google Earth Google Font Google Forms Google Images Google Map Google Photos Google Play Store Google Plus Google Print Google Reader Google Script Google Sheets Google Spreadsheet Google Translate GPRS Setting GPS Hacking Health App HelloFax Hindi Hoodie HTML Icons idea Image Editing Images IMEI Indian Railways Infographics Instagram Internet Internet Explorer Internet Tricks iOS iPad iPhone IRCTC iTunes iTV JavaScript JioCinema JioTV Junglee Kindle Language Translation Laptop Laptop. TV Life Time FREE GPRS Life-Style Link Linkedln Linux logo Make Money Online Microdoft Powerpoint Microdoft Word Microsoft Office Microsoft Outlook Mobile Mosaic Music Name Networking nexus Notepad OCR Online Shopping Open DNS OS Outlook Password PDF Petya Phillips Hue Lights Photogtraphy Pixel Play Station Podcasts Pokemon Pokemon Go Polls Print Productivity Proxy Server Pushbullet QR Code Ransomware Reddit Reliance Hack GPRS Reliance Jio RGB Ringtone Router RSS Safe Mode Samsung Galaxy S Scrabble Screen Capture Screen Sharing Screencast Secrets Security Send free sms from PC SEO Sierra Skype Slideshare SMBv1 SMS Snapchat Snapdeal Social Media Solution Sound Device Speech Recognition Sql Steam Sync Synology NAS Tata Docomo GPRS trick Teleprompter Torrent Trick Tricks TV Twitter UltraISO Unicode Unknown Extension Unlimited 2GB Unlimited 3GB Unlimited GPRS USB USB Security Key Video Editing virtual desktop Virus attack VLC Vodafone 110% working trick for GPRS Vodafone 3g Vodafone GPRS VPN wallpapers WannaCry Web Design Web Domain Website Wget Whatsapp WiFi Wikipedia Windows Windows 10 Windows 10 S Windows KN Windows Tricks windows updates Winows N Wolfarm Alpha WordPress XBox YouTube Zip
Twitter Delicious Facebook Digg Stumbleupon Favorites More