Search code examples
linuxbashshellunixrm

how to run a bash script in background automatically?


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


Solution

  • 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.