-3

I need to write a bash script that automatically deletes temp files, and runs in the background each day.

#!/bin/bash  
while true;  
do      
    rm  /home/c/temp/*
    sleep 24h
done

but it doesn't work

agc
  • 7,973
  • 2
  • 29
  • 50
user3144841
  • 11
  • 1
  • 4
  • 6
    Take a look at cron / crontab for this sort of thing .. or maybe a cron.daily file. : http://serverfault.com/questions/135906/when-does-cron-daily-run – FreudianSlip Apr 01 '16 at 14:02

1 Answers1

2

write a shell script

rm /home/c/temp/*

and add a line in the crontab

crontab -e

add the line

0 12 * * * path/to/script

It will execute you script every day at midday.

Jiri Tousek
  • 12,211
  • 5
  • 29
  • 43
John Doe
  • 354
  • 2
  • 10