Re: Maintenance Scripts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thom Paine wrote:

# Find and delete temp files
cd /home
find -name *.tmp -exec rm -f {} \;
find -name *.TMP -exec rm -f {} \;
find -name *.bak -exec rm -f {} \;


This is going to annoy people. If I create a file called something.bak and then go home it'll get deleted during the night. Actually, removing what you think might be temporary files is a Bad Thing(TM) anyway, it's better to let users do it themselves. If you're still sure you want to go ahead, do something like this:

find -type f -atime +3 \( -iname '*.tmp' -o -iname '*.bak' -o -iname '*~' \) -print0 | xargs -0 rm -f

(you might have to join lines together). This deletes likely looking files, and only files, that haven't been read in the last three days (mtime is the wrong argument, think about it). The "-print0" and "-0" make sure that filenames with spaces, newlines, whatever don't cause problems.

# Report each users home folder size
cd /home
du -c -h --max-depth=1 > /root/homesize.txt


I would think that

du -s | sort -nr > /root/homesize

(I hate those windows extensions) would be better because it'll put the biggest users at the home and only report the home directories. "-h" is nice for readability, but not so good for postprocessing. Anyway, a huge number next to your name at the top of the list is likely to be an embarrasment! (Not that it's ever happened to me you understand :-)) Of course, there's no reason to send the output anywhere, if you don't (and it's in a cron job) then the whole lot will be mailed to you -- so you could do this:

   echo
   echo DISK USAGE
   echo ==========
   du -s /home/* | sort -nr

If you're trying to control disk space, however, you might want to look at imposing quotas. Having a quota is a really good incentive to clear up your own temporary files and whatnot. There's also the advantage that since the filesystem maintains the usage structures getting a summary is very fast. Bear in mind though that you really want to over-subscribe the amount of disk space (hotels and airlines know all about this and it really does make sense, I think I used to over-subscribe by 10-25% when I enforced quotas on the 200Mb /home we had then).

# Disk Free List
df -h > /root/diskfree.txt


I find it amazingly difficult to run my eye down a list of different units and compare them.



--
Shrike-list mailing list
Shrike-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/shrike-list

[Index of Archives]     [Fedora Users]     [Centos Users]     [Kernel Development]     [Red Hat Install]     [Red Hat Watch]     [Red Hat Development]     [Red Hat Phoebe Beta]     [Yosemite Forum]     [Fedora Discussion]     [Gimp]     [Stuff]     [Yosemite News]

  Powered by Linux