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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-18-2008, 04:14 PM
|
#1
|
Member
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408
Rep:
|
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?
|
|
|
11-18-2008, 04:36 PM
|
#2
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,611
|
Quote:
Originally Posted by mohtasham1983
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...........
|
|
|
11-18-2008, 04:42 PM
|
#3
|
LQ Newbie
Registered: Nov 2008
Posts: 8
Rep:
|
Quote:
Originally Posted by mohtasham1983
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
|
|
|
11-18-2008, 04:53 PM
|
#4
|
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:
|
Quote:
Originally Posted by TB0ne
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?
|
|
|
11-18-2008, 04:58 PM
|
#5
|
LQ Newbie
Registered: Nov 2008
Posts: 8
Rep:
|
Quote:
Originally Posted by mohtasham1983
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
|
|
|
11-18-2008, 10:25 PM
|
#6
|
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:
|
Quote:
Originally Posted by michelek
inotify is tool of choice
|
Thank you very much. I installed inotify-tools and using inotifywait, achieved what I was looking for.
|
|
|
All times are GMT -5. The time now is 12:42 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|