Click to See Complete Forum and Search --> : shell script


piyocpy
10-18-2002, 12:36 AM
I don't know how to write a shell script program that can get all
the disk/file usage of each user and list them out.
eg. when enter ./eg.sh -s -r *
it can list out:

total usage user
2340231 aaa
1232132 bbb
1123343 ccc


It can accept parameters like -h (help), -s (sort on size of directory), -d (sort alphabetically on directory), -r (sort in reverse)
It can accept more than one directory on command line. All directories can be sorted together.

Can anyone write an example shell script here? or any suggestion?

Thx a lot !!!

Hena
10-18-2002, 01:52 AM
This kind of script would take a while to make so, i can't do it now (in work :)).

The command "du" should help. If run by root, you can check every users home dir with it. You can get home dirs by parsing "/etc/passwd" correctly.

z0mbix
10-18-2002, 06:06 AM
How about?:

du -sh /home/* | sort -n

brento73
10-19-2002, 02:11 AM
HOLY FSCK!!!

I'm using 6.1 GIG?!?!

*runs off to see where all this space is going*

Oh and, yeah, that sequence seems to work pretty well.

baldguy
10-19-2002, 05:48 PM
you might want to try
du -sm * | sort -n
that will keep the number in megabytes and the sort will work properly if you have someone with gigabytes of usage.