Software is like sex... It's better when it's free.

Blog - Tag 'linux'

If it can interest someone, the other day, i maked a little bash script to clean logs files on a production server (Debien here).

# Variables
nbDays=2 # Number of days after you want to delete files
password="your_root_password" # your password root
currentDate=$(date +%s)
deltaDays=$((86400 * $nbDays))
# Delete /Your/path/pattern_files
for i in /Your/path/*form0_*
    fileDate=$(date -d $(stat -c %y $i | cut -d' ' -f1) +%s)
    if [ $(expr $fileDate + $deltaDays) -gt $currentDate ]
        echo -n $password | sudo -S rm $i
Tags:  bashlinux.
Posted the Friday 24 april 2009 16:56:26 - 1 comment