LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-24-2012, 05:50 AM   #1
algreig
LQ Newbie
 
Registered: May 2012
Posts: 3

Rep: Reputation: Disabled
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
 
Old 05-24-2012, 07:01 AM   #2
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
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

Last edited by lithos; 05-24-2012 at 07:03 AM.
 
Old 05-24-2012, 07:10 AM   #3
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Jessie (Fluxbox WM)
Posts: 1,388
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
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).
 
1 members found this post helpful.
Old 05-24-2012, 07:42 AM   #4
algreig
LQ Newbie
 
Registered: May 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-25-2012, 10:14 AM   #5
algreig
LQ Newbie
 
Registered: May 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Smile 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
 
  


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
inotify and filename / directory name change events euroquisling Programming 3 05-20-2009 03:26 AM
inotify for recursive directory monitoring venkat_k Programming 4 12-24-2008 03:45 AM
LXer: Uh Oh. Another Smooth Move from Microsoft: Watch out, Ruby. Watch out OSI. LXer Syndicated Linux News 0 07-30-2007 11:46 PM
watch a folder and then print if files exist bhar0761 Linux - General 2 07-30-2005 02:05 PM


All times are GMT -5. The time now is 06:18 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration