Koozali.org: home of the SME Server

Need help with syntax

Lasse Johansson

Need help with syntax
« on: March 07, 2002, 11:42:11 AM »
I would like to do the following:

A cron-script that:

1. Creates a current list of all users on the system (Something like grep '[A-z0-9]*=user' /home/e-smith/accounts|cut -d= -f1)

2. Use that list of users as an input for something that searches the whole file system for files older than one year (something like 'find / -ctime +365 -user $user') and then creates a list of all files, their location belonging to each particular user.

3. Finally the script should mail the list of old files to each particular user, preferably with a configurable explaining message like:

"Hi! This is an automatic report from your file server. You have probably forgotten the following files, belonging to you, since I see you haven't touched them in more than one year. Please take appropriate action!"

I can execute each part "manually", but I just don't have brain enough to glue those parts together into a script!!!

Anyone out there smarter than me who could assist?
(This "feature" would probably be of interest for other people as well, I suppose...)

Regards:

Lasse

Filippo Carletti

Re: Need help with syntax
« Reply #1 on: March 07, 2002, 02:34:06 PM »
1. There should be an "official" way to obtain a user list
2. find /home/e-smith/files will be faster

for u in $(grep...)
do
find ... >/tmp/$u
if [ -s /tmp/$u ] then mail fi
rm /tmp/$u
done

Filippo Carletti

Re: Need help with syntax
« Reply #2 on: March 07, 2002, 02:47:52 PM »
Oops.
1. Your grep works, obviously.

Lasse Johansson

Re: Need help with syntax
« Reply #3 on: March 07, 2002, 06:00:24 PM »
Thanks to Filippo Carletti, I have (at last!) a working version of such a script:

Here, try it out and contribute if you like:



#!/bin/sh
#
# Script to check for files older than 365 days.
for u in $(grep '[A-z0-9]*=user' /home/e-smith/accounts|cut -d= -f1)
do
find /home/e-smith/ -ctime +365 -user $u >/tmp/$u
if [ -s /tmp/$u ]; then
mail -s"Warning, too old files!" $u <<_EOF

(This is an autogenereted message from your dear old server.)


Once in a while, I dig after files you probably have forgotten, since you haven't edited or changed them during the last year (365 days).

Well, here is your list of files you probably don't have to keep here on the server anymore. Please take appropriate action!

*****************************
$(cat /tmp/$u)
*****************************

(This procedure will run each week)

.
_EOF
fi
rm /tmp/$u
done