[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: An inotifywait question



Hi!

On Fri, 2015-04-17 at 12:05 -0400, Gene Heskett wrote:
> Greetings  all;
> 
> I am as you have proably guessed by now, the originator of some bash 
> scripts that greatly simplify the day to day background operations.
> 
> Two of these "scripts" make use of inotifywait to hand them the data they 
> need to do the rest of their jobs.
> 
> One of them watches /var/spool/mail and is dependent on finding the 
> $pidof kmail so it kmail isn't running, it will not send a message to 
> kmail over the dcop or dbus facility and thereby stuffing up the buffers 
> either of these use.
> 
> However, there are generally two instances of inotifywait running because 
> I also use a session to watch another directory where a .jar file 
> running as drivewire for a legacy computer in the basement, so that I 
> can send a file to a printer it thinks is attached to that machine, but 
> which in reality is actually sent up the usb cable to this machine and 
> dropped into a file here.
> 
> Simplified, that file, when closed by drivewire, is then sent via an lp 
> command in that script, thru cups which renders it, then sends it back 
> down that same usb cable to a brother B&W laser printer on that 
> computers desk, where it gets spit out in a beautiful font, at 19 ppm, 
> which is about 20x faster than any pin pounder printer that was ever 
> connected to it 30 years ago.
> 
> However, if something goes aglay, my scripts try to kill the inotifywait 
> session, and go silent until the proper $pidof's are present again.
> 
> But occasionally they will kill each others inotifywait sessions as I am 
> currently doing that kill with killall $name.  Not the correct way 
> obviously to kill the session that THAT script started.
> 
> Because inotifywait is not silent when it launches, I have been forced to 
> do an "var=inotifywait $option_string 2>&1 >/dev/null &" to absorb the 
> noise.  Am I dumping the PID return?  Can I save that launch return and 
> use it to do a specific "kill $savedvar"?
>
> 
> The manpage for inotifywait is silent in this regard, but I suspect I am 
> looking at the wrong manpage.  Perhaps, since its a bash script in both 
> cases, its the bash manual I should be studying?
> 
> Thanks for any clues.  The bash manual, at around 500 pages, details 
> aren't that easy to find in that tome.

Bash (or sh) is really a programming language :-)

You're looking for $! :

Special Parameters:
...
       !      Expands  to the process ID of the job most recently placed
into the background, whether executed as an asynchronous
              command or using the bg builtin (see JOB CONTROL below).


Hope this helps
-- 
Karl E. Jorgensen


Reply to: