>_ IzzyLab

Hands-on task

This task is step 8 of the course “Cron: scheduled jobs”

Cron cleans up partial downloads

medium~7 min

Abandoned partial downloads *.part keep piling up in /srv/ftp/incoming. Add a job to root's crontab that every 15 minutes deletes *.part files from this directory that were modified more than 45 minutes ago. Fresh .part files (the upload is still in progress) and any other files must not be touched. Use find.

What you'll practise:
  • cron
  • */N
  • find -mmin
  • find -name
  • automatic cleanup

Topic breakdown

Automatic cleanup is a typical cron job: every few minutes find runs, selects the garbage by conditions and deletes it. The step */15 in the minute field fires at :00, :15, :30 and :45. For thresholds in minutes find has -mmin (the + sign means "more than N minutes ago"), while -mtime counts whole days and won't do for "45 minutes". find conditions are joined with AND and evaluated left to right, so -delete goes last — otherwise it fires before the filters. The name filter (-name '*.part') keeps neighbouring files safe.

What's checked

  1. job runs every 15 minutes
  2. command deletes only old .part files

What it looks like