Register
It is currently Fri Oct 31, 2014 8:41 pm

Script to search for files, move them, send email


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Fri Oct 10, 2008 2:53 pm   

Joined: Wed Oct 08, 2008 9:40 am
Posts: 3
I need a script that will do the following:
Execute at a specific time each day. The first time it should search all the directorys of the "real" users from /etc/passwd (real=with home directory & valid shell) and that have been connected for more than three minutes. For each user, I need a list of the files larger than 10Mb, and move these files to /var/files/username. An email should be sent to each user to advise them that the files have been moved. After the first run, the script should just look at the files of each user from that day.

Thanks for any assistance!


Top
 Profile  
 PostPosted: Wed Oct 15, 2008 11:55 am   

Joined: Wed Oct 08, 2008 9:40 am
Posts: 3
Well so far this is what I've got:
I can set a crontab for the time I want to run the script each day.
Otherwise I could do something like:

if [ `date | cut -c 12-15` -e 23:55 ];
then
do script
else
echo It's not time yet
fi

To find files more than 10MB in userdir and save it as a list:
find $userdir -size +10M -type f -print > /tmp/locate.db

Anyone else want to help?


Top
 Profile  
 PostPosted: Thu Oct 16, 2008 3:54 pm   

Joined: Thu Oct 16, 2008 3:05 pm
Posts: 13
Which OS are you using?


Top
 Profile  
 PostPosted: Fri Oct 17, 2008 1:48 am   

Joined: Wed Oct 08, 2008 9:40 am
Posts: 3
I'm using Debian although I'd like it work on other distros.


Top
 Profile  
 PostPosted: Mon Oct 20, 2008 2:03 pm   

Joined: Thu Oct 16, 2008 3:05 pm
Posts: 13
why not try
cat /etc/passwd | awk -F : '{print $1}' | while read user;do find /home/$user -size +10M -type f -print > /var/files/$user;cat /var/files/$user| while read line;do /bin/mv $line /var/files/$user;done
mail $user -S "Moved Files" < /var/files/$user;done

and all you would need is the email addresses for the users.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP