Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Script for calculating disk usage

Posted on 2006-04-04
7
Medium Priority
?
834 Views
Last Modified: 2013-12-16
Hi,
I have home folders under /export/home/*.
I need to have  script that will check for disk usage of each folder, user1. Test to see if its over 2GB and if it is then mail the owner of the folder say tom@mydomain.com. This will have to be done recursively for all users in the directory /export/home.

Thanks,
--Walter
0
Comment
Question by:wfaleiro
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 6

Expert Comment

by:mightyone
ID: 16382586
0
 
LVL 6

Expert Comment

by:mightyone
ID: 16382693
if not use something like this, as for the time beeing i am on windows client you will have to alter alot

:-)
function sendmail has to be added by you,try 'man mail' for hints. but still think using quota is better

#!/bin/sh
#loop dirs
for i in `ls -al /export/home` do
  #check size
 if [ du -sh $i -gt 2000000000 ]; then
  echo "$i is full"
  sendmail($i)
  fi
done

0
 
LVL 1

Author Comment

by:wfaleiro
ID: 16384207
Hi,
I cannot use quotas as it will be implemented on an entire parition. The home directory is a sub directory on the partition, with other directories like source for cvs present. These will also come into picture when quotas are implemented.

Regards,
--Walter
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 16389407
du -h  /export/home/user1 | awk -F/ 'NF==3{print}'
du -h  /export/home/ | awk -F/ 'NF==3{print}'
0
 
LVL 1

Author Comment

by:wfaleiro
ID: 16405577
That produces no output at all.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16406358
please post some lines from (10 or so, at least containing one with just a directory path)
  du -h /export/home/user1
0
 
LVL 14

Accepted Solution

by:
cjl7 earned 200 total points
ID: 16476462
Hi Tom,

Here is a script that will do what you want, "fix" the SUBJECT and the BODY. You might wanna add the "@mydomain.com" after $i in "mail $i..."

//jonas

#!/bin/bash

# limit
LIMIT=42000 #2GB
SUBJECT="Your homedir is to large"
BODY="You need to delete stuff..."
cd /export/home/
for i in *
do
TEST=`du -sk $i|awk '{print $1}'`
if [ $TEST -gt $LIMIT ]; then
mail $i -s "$SUBJECT" <<EOF
$BODY
EOF

fi
done
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension . This reminded me of questions that come up here at EE along the lines of, "How can I tell the type of file from its cont…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question