Cron job fails about once a week ??

Discussion in 'Site & Server Administration' started by Kerosene, Nov 5, 2007.

  1. #1
    I have a cron job set to delete everything in a garbage directory every day.
    Most of the time it works, but once last week, and again today, for what appears to be no reason it didn't work.

    My cron:
    rm -rf /home/accountname/garbage/*

    The error I got (via email)
    /bin/sh: /bin/rm: Argument list too long

    Any ideas?
     
    Kerosene, Nov 5, 2007 IP
  2. ndreamer

    ndreamer Guest

    Messages:
    339
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    how many files are in the directory ?
     
    ndreamer, Nov 5, 2007 IP
  3. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #3
    It depends. Sometimes 500, sometimes 1500+. Depends on how much traffic the site gets per day.
    The directory is used for a cache.
     
    Kerosene, Nov 5, 2007 IP
  4. plumsauce

    plumsauce Peon

    Messages:
    310
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    are you using wildcards?

    otherwise, have the email also send you the argument list.

    maybe the obvious has happened and the diagnostic message really is telling the truth. too many file names for the command to run.
     
    plumsauce, Nov 5, 2007 IP
  5. InFloW

    InFloW Peon

    Messages:
    1,488
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You're reaching the max # of files that can be listed in the rm queue if my memory serves me right. The solution to this is to use a command like find to grab the files and then pipe them over to rm so it can remove them at a more reasonable level at a time.

    So I believe this would do the trick

    find /home/accountname/garbage/ -type f -maxdepth 1 | xargs rm -n100


    n will control the number of arguments to send to rm and it does not delete other directories or symbolic links.


    Of course I make no guarantee this will work best to test it of course before running it in a live environment.
     
    InFloW, Nov 5, 2007 IP