LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   inotify to watch a directory then print and move (https://www.linuxquestions.org/questions/linux-newbie-8/inotify-to-watch-a-directory-then-print-and-move-946606/)

algreig 05-24-2012 05:50 AM

inotify to watch a directory then print and move
 
Hi,

I am new to the scripting idea, and I need to create a script to do the following. (A bit of background) I want to use cheese as a photo booth at a major family function. After each photo is taken it is saved by cheese to ~/Pictures/webcam, each picture is named with a timestamp only. The idea is to automate the printing of each photo so that all the guests have to do is pose and shoot, and then the printer will print 2 copies of each, and once printed they can be moved to the ~/Pictures/webcam/printed folder. I am using a HP printer with a Printer name of Photosmart-C5200-Series.

What would be a good way to achieve this, please?

Andrew Greig
Melbourne Australia

lithos 05-24-2012 07:01 AM

Hi,

what I can't provide you the exact commands, but with incrond/inotify you should be able to monitor directory for changes
then create a script to run on an event that inotify generates (let's say new file added: IN_CREATE).

- How to Monitor directory for changes

The script would be just :
Code:

mv "~/Pictures/webcam/filename" "~/Pictures/webcam/printed/"
some example I have posted but not exactly what you're asking

good luck

neonsignal 05-24-2012 07:10 AM

You could do it this way:
Code:

inotifywait -m -e close_write ~/Pictures/webcam --format "%w%f" | \
while read filename; do lpr -P Photosmart-C5200-Series "$filename"; mv "$filename" ~/Pictures/webcam/printed; done

The inotifywait (part of the inotifytools package) waits for writes to the folder. The '-m' flag makes it run indefinitely (instead of running it in a script loop which could mean it might miss an event). The '--format' outputs only the file names that were written.

The output of the inotify is piped to a while loop (alternatively xargs could be used to run a command for each filename input). The while loop reads the filename from standard input, prints it to the printer, and then moves it to the destination directory.

If you are using CUPS for your printing, then there are some image processing options that can be specified if the default is not what you want.

(I noticed your question on the MLUG list, but hadn't had a chance to respond).

algreig 05-24-2012 07:42 AM

Work to be done now, thanks
 
I am very grateful for the rapid responses and for the explanation of the instructions. I will not get a chance to work on this, now until Saturday, but I am quite excited about the prospects.

Andrew Greig

algreig 05-25-2012 10:14 AM

To Neonsigmal - Thanks
 
Hi Neonsignal,

i cut and pasted your script into a console, and the lack of response indicated i needed to d/l inotify tools, that done, the script worked perfectly the first time. It's a beautiful thing, thank you for your efforts on this, I am so relieved that I will now be ready for the party.

Yours faithfully
Andrew Greig
Melbourne Australia


All times are GMT -5. The time now is 05:29 AM.