LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 05-31-2012, 12:43 AM   #1
michaelfisk
Member
 
Registered: May 2012
Posts: 32

Rep: Reputation: Disabled
Auto print new files in folder


I am very new to Linux but I want to be able to have Ubuntu set up so that whenever a new file is added via Dropbox to a folder it will automatically print to multiple Bluetooth printers. Is this difficult? Any advice? Thanks guys!
 
Old 05-31-2012, 01:06 AM   #2
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,591

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233
Hi,

this sounds like a job for incron. Basically incron can be configured to take certain actions based on filesystem events.

Assuming that you already have your printers configured in cups, and lets say they are called "printera" and printerb", you could write a script, let's call it "autoprint", like:
Code:
#!/bin/sh
fname="$1"

# Assuming that you only want to print pdf files, check it is a pdf
# otherwise do nothing
if [ $(file -b --mime-type "$fname") != "application/pdf" ] ; then
  exit 0
fi  

lpr -P printera "$fname"
lpr -P printerb "$fname"
Now put that script somewhere, eg /usr/local/bin/multiprint and make it executable.
Code:
chmod +x /usr/local/bin/multiprint
Next install incron:
Code:
sudo apt-get install incron
Next add an incrontab entry (here I assume the location the files will appear in is "/home/foo/DropBox/printme"). To do this open up
a text editor an make a little oneline file like the following.
Code:
/home/foo/DropBox/printme IN_CLOSE_WRITE /usr/local/bin/autoprint $@/$#
Save it in /etc/incron.d with a descriptive name, eg
/etc/incron.d/autoprint

Now (after restarting incron) any files appearing in /home/foo/DropBox/printme will be processed by the /usr/local/bin/autoprint script.

There is a fair bit of stuff covered here, and some of the finer details have been skipped but hopfully this is enough to get you started.

Evo2.
 
Old 05-31-2012, 01:16 AM   #3
michaelfisk
Member
 
Registered: May 2012
Posts: 32

Original Poster
Rep: Reputation: Disabled
Wow thanks a lot for the quick response. Much of this is foreign to me but I'll jump in and see how it goes. Another thing I would like to do is not only have it auto print new files in a folder but also take information in the file and lay it out in the print. For example this will auto print instagram photos, so on the print I would like to include the title of the image, description and user name as well as the image.

So basically on the print itself it should have this information:

User name
Image
Comments (hashtags, etc)

Do you think this is possible?
 
Old 05-31-2012, 01:26 AM   #4
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,591

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233
Hi,

it is possible, but it will take a little more scripting. I guess the information you are interested in is stored as exif data, so you can use tools like exiv2 to extract the information in a shell script and then use some other tool to produce a pdf (or ps or something else) file that contains the image and the text. All of this could be done in the shell script that I called "multiprint".

I'd probably use latex for combining the image and text, but that is just because it is what I know. There are surely better options for this last step.

Evo2.
 
Old 05-31-2012, 01:28 AM   #5
michaelfisk
Member
 
Registered: May 2012
Posts: 32

Original Poster
Rep: Reputation: Disabled
Ok, awesome thank you very much. If I've gotten to far over my head do you know the best place to find someone I could hire to write these scripts for me?
 
Old 05-31-2012, 04:17 AM   #6
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,591

Rep: Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233Reputation: 1233
Hi,
Quote:
Originally Posted by michaelfisk View Post
Ok, awesome thank you very much. If I've gotten to far over my head
Hmm, if you've already worked out how to setup cups, and have a little scripting experience you should be able to get it to work.
Quote:
do you know the best place to find someone I could hire to write these scripts for me?
I'm sure there are plenty of people who would be happy to take your money and root password...
Just kidding. No, sorry, I don't know where you should look for such a contractor.

Evo2.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] create sub-folder from folder name and transfer files on the fly BoydRice Linux - General 5 03-07-2012 08:44 PM
[SOLVED] Using terminal command -Find files in a folder and copy them to a different folder j-jock Linux - General 4 11-28-2011 03:20 AM
[SOLVED] How to list folder size, and number of files and folders in folder steven.c.banks Linux - General 3 11-24-2010 07:24 AM
Auto-print an email with photos wackychimp Linux - Newbie 4 05-02-2008 02:05 PM
watch a folder and then print if files exist bhar0761 Linux - General 2 07-30-2005 03:05 PM


All times are GMT -5. The time now is 10:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration