in reply to Extract data based on dates and place in new file

If I understand you correctly, your script works if you call it on the command line, but not as a cron job. That is usually because cron has a different environment, i.e. a different current working directory, a different PATH ...

For example it might have problems finding executables the script is depending on

  • Comment on Re: Extract data based on dates and place in new file

Replies are listed 'Best First'.
Re^2: Extract data based on dates and place in new file
by dtbach (Novice) on Aug 10, 2011 at 20:03 UTC
    The way the script works now it is using STDIN for starting and ending dates, so I input 20110809 and 20110816 (when I run it on 20110817) and it will extract the information between those dates and output to a file I call dfile. I want the cron job to call the script and automatically capture the required data and send it to the dfile without having to input the dates.

      Ok, so you need to change the script so that it calculates the dates of today and a week before today, instead of getting it from stdin, right? localtime(time()) will give you an array where you can extract year, month and day of today, subtract 7*24*60*60 from time() and you will get the date of one week before.

      If that isn't what you are looking for, be more specific what you want or what isn't working. Post the relevant code. Use the right tags so we can read it, How (Not) To Ask A Question

      "...send it to the dfile without having to input the dates. "

      Looks like this is a different question than originally posted?

      Seems that way to me.

      So, check CPAN for modules with "Date" and/or "Time" -- after all, something needs to tell the script that you want Cron to run which dates to check...

      Or, re-write your script with the ASSUMPTION that Crom will run it shortly after midnite; calculate the desired dates from gmtime or localtime, as appropriate.