Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a cron job which unzips a file and executes it. The cron is set to unzip, execute and delete the .zip file after. It's executing fine but it's not deleting the file. Here's the cron:

/usr/bin/wget -q -nd --delete-after 'url of plugin to execute the file'

I tried to add a second cron which would delete the files that are older than 15 days from the folder but this seems to "bother" the first cron to execute properly.

The second cron I used was:

/usr/bin/find /directory/ -mtime +15 -exec /bin/rm {} \; > /dev/null 2>&1
share|improve this question
    
Post your entire first cron script. There is nothing in your wget line that actually executes anything. --delete-after is really not indented for what you are trying to use it for - see the man page. –  didster Oct 17 '12 at 20:32
    
the entire line is : /usr/bin/wget -q -nd --delete-after 'URL/index.php?option=com_fwrealestate&task=processPlugin&plugin=importmls' –  Petros Oct 17 '12 at 20:41
    
You definitely want to check a question of mine. It has an answer by Stephane Chazelas that explains how you can create an interactive shell that is identical to the environment your cron job will see. If you walk through his little procedure, you get a prompt and you can test your cronjob step by step and see where it fails. unix.stackexchange.com/a/56503/16841 Sure it isn't a 100% match for your question, but it can help you troubleshoot crontab issues. –  jippie Nov 23 '12 at 22:58
    
Read the wget man page and study the meaning of --delete-after. It deletes all downloaded files immediately after downloading them; it doesn't give you a chance to do anything with them. (It's useful for pre-fetching pages through a proxy.) –  Keith Thompson Dec 16 '12 at 22:02

1 Answer 1

I'd do something like this:

#!/bin/sh
# 

/usr/bin/wget -q -nd --delete-after 'url of plugin to execute the file'
if [ $? = 0 ] ; then
  /usr/bin/find /directory/ -mtime +15 -exec /bin/rm {} \; > /dev/null 2>&1
fi

feel free to modify it for your needs

share|improve this answer
    
should I put this in cron? –  Petros Oct 18 '12 at 0:08
    
copy and paste that into a file, chmod 755 it and THEN put it into a cron –  alexus Oct 18 '12 at 13:58
    
It seems like it's working. Thanks! However, I also have setup to receive an email every time the wget cron runs but I am not receiving it. Would you know why? –  Petros Oct 19 '12 at 4:53
    
check your logs, you'll find your answer there –  alexus Oct 19 '12 at 14:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.