Tuesday, November 10, 2009

bash script to delete users directorys older then 14 days

#!/bin/bash

### Declare array ###
ARRAY=( `ypcat passwd | awk -F: '{print $1}'` )

### Get number of elements in the array ###
ELEMENTS=${#ARRAY[@]}

### Delete folders older then 14 days in users directory ###
for (( i=0;i<$ELEMENTS;i++)); do
/usr/bin/find /nas/data/accelrys/pp/web/jobs/"${ARRAY[${i}]}" -mtime +14 -exec rm -rf {} \;
done

No comments: