LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-18-2008, 04:14 PM   #1
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408

Rep: Reputation: 30
Running a script upon a file is added to a directory


Hi,

I have a CUPS based printer that holds all print job it receives. However, there are certain print jobs that I want to print immediately. The print job file name is the only way of distinguishing such files from others, so it's impossible to configure CUPS to handle such action as far as I know.

I know that all print jobs go to a certain directory on the server, once they're received. That is, I want to know if there's any way a script that takes care of releasing print job, can be ran once a new file is created in a directory.

I tried to use cron job for this purpose, but I cannot set the cron job time period to less than a minute. I need something that can be invoked immediately.

Any idea?
 
Old 11-18-2008, 04:36 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,693

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by mohtasham1983 View Post
Hi,

I have a CUPS based printer that holds all print job it receives. However, there are certain print jobs that I want to print immediately. The print job file name is the only way of distinguishing such files from others, so it's impossible to configure CUPS to handle such action as far as I know.

I know that all print jobs go to a certain directory on the server, once they're received. That is, I want to know if there's any way a script that takes care of releasing print job, can be ran once a new file is created in a directory.

I tried to use cron job for this purpose, but I cannot set the cron job time period to less than a minute. I need something that can be invoked immediately.

Any idea?
How about a sleep statement in your bash script? Run it with "nohup <script name> 2>&1&", so it backgrounds and starts a new process. Can get to every 1 second with sleep...........
 
Old 11-18-2008, 04:42 PM   #3
michelek
LQ Newbie
 
Registered: Nov 2008
Posts: 8

Rep: Reputation: 0
Quote:
Originally Posted by mohtasham1983 View Post
Hi,

I tried to use cron job for this purpose, but I cannot set the cron job time period to less than a minute. I need something that can be invoked immediately.

Any idea?
inotify is tool of choice
 
Old 11-18-2008, 04:53 PM   #4
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by TB0ne View Post
How about a sleep statement in your bash script? Run it with "nohup <script name> 2>&1&", so it backgrounds and starts a new process. Can get to every 1 second with sleep...........
Can you explain more about the "2>&1&" option? What do 2 and 1 mean here?

Also, doesn't it use a lot of resources?
 
Old 11-18-2008, 04:58 PM   #5
michelek
LQ Newbie
 
Registered: Nov 2008
Posts: 8

Rep: Reputation: 0
Quote:
Originally Posted by mohtasham1983 View Post
Can you explain more about the "2>&1&" option? What do 2 and 1 mean here?

Also, doesn't it use a lot of resources?
2>&1 means that error output (2) will be redirected to standard out (1).
and last ampersand says to execute in background.

I suggest You look at inotify wiki page
 
Old 11-18-2008, 10:25 PM   #6
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by michelek View Post
inotify is tool of choice
Thank you very much. I installed inotify-tools and using inotifywait, achieved what I was looking for.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
running a script from default directory Ian D Linux - General 5 06-17-2008 03:04 PM
No Such File or Directory when running the script just_a_kid Linux - Newbie 7 01-25-2007 01:13 PM
monitoring file added to a directory / subdirectories abhi_abhijith Programming 4 02-13-2006 07:25 AM
Running a script on every file in a directory davee Linux - Newbie 2 11-04-2003 02:34 PM
Running a shell script when a user is added. jayakrishnan Linux - General 5 04-29-2002 02:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:43 PM.

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
Open Source Consulting | Domain Registration