calculate the space

Hi everyone,

I need to write a script to calculate the space for sub-folders under /home:

Here is the scanrio:

cd /home
drwxr-xr-x 57 root root 8192 Jan 22 16:13 home_1
drwxrwxrwx 69 root root 8192 Jan 29 10:36 home_2
drwxr-xr-x 97 root root 8192 Nov 21 14:40 home_3
drwxr-xr-x 80 root root 8192 Jan 30 13:38 home_4
dr-xr-xr-x 1 root root 1 Feb 9 13:14 home_5
dr-xr-xr-x 1 root root 1 Feb 9 13:14 home_6
dr-xr-xr-x 1 root root 1 Feb 9 13:14 home_6
dr-xr-xr-x 1 root root 1 Feb 9 13:14 home_7
.
.
.
goes upto

dr-xr-xr-x 1 root root 1 Feb 9 13:14 home_23
I need to cd to each home dir and check for all folders where owner is a number and calculate it's size using "du -sk" command.

# cd home_1

ls -l
drwxr-xr-x 16 16848 eaq 4096 Sep 10 08:22 khanbx0c
drwxr-xr-x 21 17341 eao 12288 Oct 29 2006 labatlx
drwxr-xr-x 6 lasisiog eal 4096 Feb 4 07:25 lasisiog
drwxr-xr-x 14 lecailpx eau 4096 May 2 2007 lecailpx
drwxr-xr-x 14 16460 eao 4096 Oct 21 13:03 littleax
drwxr-xr-x 28 logtrak eaq 8192 Jul 2 2007 logtrak
drwxr-xr-x 2 17480 eap 4096 Feb 17 2007 megrinan
drwxrwxrwx 64 navaraam eaq 12288 Feb 6 15:47 navaraam
drwxr-xr-x 31 17501 eac 8192 Jul 2 2007 olaqiaa
drwxrwxr-x 104 owback easdmm 94208 Feb 6 13:25 owback
drwxr-xr-x 14 16490 ehe 4096 Nov 30 2004 patvalza
drwxr-xr-x 33 sagazt qcd 8192 Jan 30 17:04 sagazt
drwxr-xr-x 9 sanniml ehh 4096 Oct 22 14:27 sanniml
drwxrwxr-x 2 root root 4096 Jul 21 2004 seismic
drwxr-xr-x 9 shehriih eqc 4096 Nov 21 2006 shehriih
drwxr-xr-x 2 ssglusr ssd_ssg 4096 Oct 4 2005 ssglusr
drwxr-xr-x 2 17602 ehh 4096 Jun 3 2007 suicmevs
drwxr-xr-x 6 17436 eap 4096 Apr 7 2007 suwaiiah
drwxr-sr-x 77 wasimx eaf 24576 Feb 6 15:28 wasimx
drwxr-xr-x 12 16504 ehd 4096 Oct 21 13:03 xiaojx
drwxr-xr-x 3 17309 eap 4096 Dec 5 2006 youngsj
drwxr-xr-x 37 17406 qst 12288 Apr 3 2007 zambraga
drwxr-xr-x 47 zarmm eag 12288 Feb 5 10:47 zarmm
drwxrwxr-x 49 16531 eao 16384 Jun 14 2007 zegdra0a

I need to capture home directories where owner is just a number:

example:
drwxr-xr-x 37 17406 qst 12288 Apr 3 2007 zambraga

than run du -sk on those one by one by using echo:

zambraga         131040

Any tips would be appreciated.

#!/bin/sh
for directory in `ls -ld home_*/* | awk '{ print $3":"$9 }'`
do
    if echo $directory | cut -d ':' -f 1 | grep -iv [a-z] > /dev/null
    then
        du -sk `echo $directory | cut -d ':' -f 2`
    fi
done

Untested

Hi Smiling Dragon,

Thanks for your help .. it works for me !!! Appreciate that.

Hi guys, need a quick help on this ... how can I get the following output into different columns like:

16862 868K /home/home_1/abbama0z
16791 8.9M /home/home_1/ahmaha0d
.... and so on ..

instead of the following:

16862
868K /home/home_1/abbama0z
16791
8.9M /home/home_1/ahmaha0d
16841
32K /home/hom_2/ajajaa0j
16915
89M /home/home_2/aljabeaa
17176
32K /home/home_2/alsaeeaj
17013
32K /home/home_3/alzairam
16646
1.7M /home/home_3/amairam
16847
842M /home/home_3/apontejc
16512
1.4M /home//home_3argaudmj
17005
1.4M /home/home_3/asiriks
16984
32K /home/home_4/bajaas0a

Appreciate your help ....

This should give the desired output:

awk '{ORS=NR%2?" ";"\n"}1' file

Start a new thread for a new question next time instead of hijack your own thread.

Regards

Thanks for the input, but how can I get this from running the above mentioned script in this thread.

I did not hijack the thread, this question is related to the same thread and the script which generates this output is also there so I wanted to make it easy if someone needs to see the script.

I hope this clarifies your concern.

Pipe the output of your script to the awk command:

scriptname | awk '{ORS=NR%2?" ";"\n"}1'

Regards

while running as following:

./script | awk '{ORS=NR%2?" ";"\n"}1'

getting the following error:

awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1
Broken Pipe
Broken Pipe
Broken Pipe
Broken Pipe

Any idea please !!

Thanks.

Use nawk or /usr/xpg4/bin/awk on Solaris.

Regards