EHLO!
This started like a "hey, give me 30 minutes" but here I am a day after. Basically what I want to do is to check "/var/log/messages" for 30 seconds and when someone plug-in a USB hard disk during that time, execute some commands.
So I am using Per function "File::Tail", and kinda works but I don't know how to run it for just 30 seconds, tail stays there until I manually exit( It works just as tail command). I been looking for solutions using fork but still no luck or experience on it. Part of the "tail" code is like this:
while ((defined($line=$file->read)) ) {
I appreciate any help or tip. If anyone has another solution using another, function or what ever, it's fine, I need the code for a "CGI".
You can achieve this using File::Tail::select().
The example below puts one seconds worth of the tailed file into the
@pendingarray which is then processed. Looping 30 times will give you very close to 30 seconds (dependend on how active your /var/log/messages is). If you require more precise timing you can store the time before the loop and compare how long has passed on each iteration.