Results 1 to 14 of 14
  1. #1
    ...and a Pirate's heart. Convergence's Avatar
    Join Date
    June 24th, 2005
    Posts
    6,918
    Using CRON job to delete zip files
    Have a CRON setup to download merchant zip files (when gzip is not available) at specific times throughout the day.

    Another scheduled CRON first extracts / inflates the content in the zip files and then imports them into the database.

    However, am always left with the original zip file. Have been unable to find any CRON flag/command to delete the unneeded zip files.

    gzip is GREAT (merchants/networks please provide all feeds in gzip as an option) as once they are extracted they are deleted.

    Any suggestions?

    Thanks!
    Salty kisses, Sandy toes, and a Pirate's heart...

  2. #2
    ABW Veteran Mr. Sal's Avatar
    Join Date
    January 18th, 2005
    Posts
    6,795


    Any suggestions?
    Maybe with this bump more people will see the thread...

  3. Thanks From:

  4. #3
    Moderator
    Join Date
    April 6th, 2006
    Posts
    2,689
    .. long weekend here, it was Canada Day

    What about adding a line to the script using the find command, then rm {}..?

    eg. find -name *.zip -exec rm {} \;

    I'm actually working with a sizable group of files today, using the above technique.. have messed up too many times with the "move" command, so now I copy first, then delete once I verify everything is ok.

  5. #4
    ...and a Pirate's heart. Convergence's Avatar
    Join Date
    June 24th, 2005
    Posts
    6,918
    Quote Originally Posted by teezone View Post
    .. long weekend here, it was Canada Day
    Happy Canada Day - eh!

    Quote Originally Posted by teezone View Post
    What about adding a line to the script using the find command, then rm {}..?

    eg. find -name *.zip -exec rm {} \;

    I'm actually working with a sizable group of files today, using the above technique.. have messed up too many times with the "move" command, so now I copy first, then delete once I verify everything is ok.
    By "adding a line to the script" do you mean our software or the CRON itself?
    Salty kisses, Sandy toes, and a Pirate's heart...

  6. #5
    Moderator
    Join Date
    April 6th, 2006
    Posts
    2,689
    Happy Canada Day - eh!
    Thanks! It's been a fab weekend...
    By "adding a line to the script" do you mean our software or the CRON itself?
    I guess it depends on the process.

    I have a php script (running daily via CRON) that does a clean-up at the end of a download... so in theory, you could insert the 'delete' command between the unzip & import.

    At the same time, you could simply add the above command to CRON, without the need for a script.

  7. #6
    ...and a Pirate's heart. Convergence's Avatar
    Join Date
    June 24th, 2005
    Posts
    6,918
    Quote Originally Posted by teezone View Post
    At the same time, you could simply add the above command to CRON, without the need for a script.
    That's what we're looking for.

    We have the following CRON to unzip:

    Code:
    cd /path/to/our/feeds/folder/;unzip -n \*.zip;
    So just add
    Code:
    find -name *.zip -exec rm {} \;
    afterwards?

    No escaping the *.zip?

    Will this delete all zip files or are we forced to name all 10 of them?

    Thanks!
    Salty kisses, Sandy toes, and a Pirate's heart...

  8. #7
    Moderator
    Join Date
    April 6th, 2006
    Posts
    2,689
    Yup, that should do it.. just need to specify the location of zip files... this command should delete them all:

    Code:
    find /path/to/our/feeds/folder/ -name *.zip -exec rm -rf {} \;
    I usually send the results of CRON jobs to a txt file, to help troubleshoot (have added too many jobs that didn't execute!).

    Code:
    find /path/to/our/feeds/folder/ -name *.zip -exec rm -rf {} \; > /path/to/our/feeds/folder/output.txt
    If the job doesn't work, output.txt will contain the reason why (permissions, no files found, etc).

  9. Thanks From:

  10. #8
    ...and a Pirate's heart. Convergence's Avatar
    Join Date
    June 24th, 2005
    Posts
    6,918
    Thanks, Teezone!

    Will put it in after dinner (back to monitoring the ribs)...
    Salty kisses, Sandy toes, and a Pirate's heart...

  11. #9
    ...and a Pirate's heart. Convergence's Avatar
    Join Date
    June 24th, 2005
    Posts
    6,918
    Hi Teezone,

    Added:

    Code:
    find /path/to/our/feeds/folder/ -name *.zip -exec rm -rf {} \;
    and received this error:

    find: paths must precede expression
    Usage: find [-H] [-L] [-P] [path...] [expression]
    So, figured I'd move the path

    Code:
    /path/to/our/feeds/folder/ find -name *.zip -exec rm -rf {} \;
    and received this error:

    /bin/sh: /path/to/our/feeds/folder/: is a directory
    Realized that the unzip was already in that directory so changed it to:

    Code:
    find -name *.zip -exec rm -rf {} \;
    and received this error:

    find: missing argument to `-exec'
    And that's where we are LOL

    Any additional suggestions?
    Salty kisses, Sandy toes, and a Pirate's heart...

  12. #10
    Moderator
    Join Date
    April 6th, 2006
    Posts
    2,689
    I think part of the string needs to be placed in single quotes when running in CRON, but we can make it easier...

    Try replacing
    Code:
    -exec rm -rf {} \;
    with
    Code:
    -delete
    I just tested the above on my own CRON, seems to have worked!

    Added: For anyone interested in the difference between the above and a standard "delete" command, you have to use find & -exec/-delete if you receive an error message "Argument list too long" (ie. if you're working with thousands of files). I just got into the habit of using it for everything.
    Last edited by teezone; July 3rd, 2012 at 12:05 AM.

  13. Thanks From:

  14. #11
    ...and a Pirate's heart. Convergence's Avatar
    Join Date
    June 24th, 2005
    Posts
    6,918
    You're beautiful!

    Thank you for your help - works perfectly...
    Salty kisses, Sandy toes, and a Pirate's heart...

  15. Thanks From:

  16. #12
    ABW Ambassador
    Join Date
    January 18th, 2005
    Posts
    1,744
    Well Done, teezone! This is the type of helpful threads I love to see at ABW.

  17. Thanks From:

  18. #13
    Moderator
    Join Date
    April 6th, 2006
    Posts
    2,689
    Awww, thanks for the nice words!! I'm not a programmer per se, but have picked up an assortment of tricks like the above... it makes publishing a bit easier

    And Convergence, it's the least I could do for all your help with my 301/404 issue!!

    Speaking of that thread, I'll post an update soon.. there have been some interesting developments.

  19. Thanks From:

  20. #14
    ABW Ambassador purplebear's Avatar
    Join Date
    January 18th, 2005
    Posts
    3,960
    awwh, darn, guess is too late for me to help ya convergence

    teezone you are definitely on my list of computer smarties (Group of very, very smart people who I envy very much. To say my computer skills are very limited is a big understatement so am in complete awe of all of you)

    Practically every word said is Martian talk to me. lol

    DEFINITELY agree with msladybug Afraid still is no hope for me but am sure is very helpful to a lot of others

    Glad you got your problem fixed convergence

  21. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Broken Datafeeds (zip files with gz extension)
    By isellstuff in forum Google Affiliate Network - GAN
    Replies: 23
    Last Post: June 9th, 2010, 05:04 PM
  2. Help setting my cron job!
    By Ricardo Dacosta in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: June 19th, 2008, 09:35 AM
  3. Hostgator Cron Job
    By Code Monkey in forum Midnight Cafe'
    Replies: 3
    Last Post: June 2nd, 2008, 08:30 PM
  4. Cron Job Question
    By Doug247 in forum Programming / Datafeeds / Tools
    Replies: 9
    Last Post: March 18th, 2008, 01:13 PM
  5. Cron job
    By templus in forum ShareASale - SAS
    Replies: 22
    Last Post: July 29th, 2007, 03:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •