Yeah, here's an approach I came-up with based on the
file command:
Code:
#!/bin/sh
if file $1 | egrep "PDF|Microsoft" > /dev/null ; then
exit ; else
rm -f $1
fi
Let's say you name it
auto-delete.sh and place it in root's home folder. To have the script run every night at 10:30PM you could call this script from root's crontab like:
Code:
30 22 * * * find /home/example -type f -exec /root/auto-delete.sh {} \; > /dev/null 2>&1
Where
/home/example is the directory you wanna check (recursively). The script as posted would delete any files that aren't either PDF or Microsoft (I tested it with Excel and Word files). You can easily add matches for other file types. A couple things you might wanna consider are moving the files instead of deleting them (as a safeguard) and having the script generate a log of what it does (and perhaps have it email it to you).
EDIT: Here's an example with logging:
Code:
#!/bin/sh
if file $1 | egrep "PDF|Microsoft" > /dev/null ; then
echo `date` $1 IGNORED >> /var/log/auto-delete.log ; exit ; else
echo `date` $1 REMOVED >> /var/log/auto-delete.log ; rm -f $1
fi
I just noticed, however, that my approach has issues when it comes to files with spaces in their names. =(