Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Directory Questions - How would I do this?

by jdlev (Scribe)
on Jan 20, 2009 at 19:42 UTC ( [id://737652]=perlquestion: print w/replies, xml ) Need Help??

jdlev has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I've got a unique situation. I'm trying to get perl to monitor a database file. Basically, I'm starting the program and having it sleep 30 minute and then check the database again for a new record. What I need to do is any time there is a new record found, it creates a file.

---Everything works up to this point--- The part I don't know how to do is have another program monitor that folder where the new files are created. When a new file is created, it needs to be emailed to another person. I've got the emailing attachments side of things down. I don't know how to get a perl program to monitor the file folder, and when a new file pops up, it will email only that file to the customer. Any help is appreciated!

I love it when a program comes together - jdhannibal
  • Comment on Directory Questions - How would I do this?

Replies are listed 'Best First'.
Re: Directory Questions - How would I do this?
by BrowserUk (Patriarch) on Jan 20, 2009 at 20:01 UTC
    The part I don't know how to do is have another program monitor that folder where the new files are created.

    Why not have the program that creates the file do the emailing? Or if you think that will take longer than the 30 seconds that it would normally sleep for, have it create the file and then run (detach) the program that will do the emailing.

    That way, the email program doesn't have to sit and poll a directory, it just gets run when required, with the name of the file to email being passed as a parameter.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Director Questions - How would I do this?
by jasonk (Parson) on Jan 20, 2009 at 19:47 UTC
Re: Directory Questions - How would I do this?
by derby (Abbot) on Jan 20, 2009 at 20:01 UTC

    Well ... if you're creating a file based on database input, why do you need a separate process to monitor the directory? Couldn't emailing the person be the next step:

    1. do sql 2. if ( new record ) 2a. save file to directory 2b. email interested user
    And I would probably place something like this in cron over sleeping for 30 minutes.

    -derby
      I'm very new to programming, so I have no idea how sql would know what a new record was. The database it pulls from is read only, so I can't update anything there.
      I love it when a program comes together - jdhannibal
        I have no idea how sql would know what a new record was.

        I think we assuming from your original post that you were already getting the new records from the database, and that you were probably using some sort of SQL to retrieve the records. Not being familiar with the database, I couldn't say what that SQL was (or even whether or not it's a SQL database), so I hope you do have some way of getting the new records

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://737652]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found