Sponsored Content
Full Discussion: calculate the space
Top Forums Shell Programming and Scripting calculate the space Post 302165823 by za_7565 on Saturday 9th of February 2008 05:32:17 AM
Old 02-09-2008
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.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

wake up user space thread from kernel space ISR

Hello, I'm searching for a proper way to let the kernel space ISR(implemented in a kernel module) wake up a user space thread on a hardware interrupt. Except for sending a real-time signal, is it possible to use a semaphore? I've searched it on google, but it seems impossible to share a... (0 Replies)
Discussion started by: aaronwong
0 Replies

2. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

3. Shell Programming and Scripting

calculate swap space usage in Solaris and converts it in Percentage

Hi Folks, I am looking for a way to write a script to calculate swap usage in Solaris so that the current usage will be shown in Percentage value. Thanks!! Based on 'swap -s' command # swap -s total: 1378936k bytes allocated + 1236880k reserved = 2615816k used, 2725104k available (2 Replies)
Discussion started by: jaapar
2 Replies

4. Shell Programming and Scripting

Calculate age of a file | calculate time difference

Hello, I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes... I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes. To do... (10 Replies)
Discussion started by: worm
10 Replies

5. Linux

How to reclaim the space which i used to increse the swap space on Xen,

Hi, i have done a blunder here, i increased the swap space on Xen5.6 server machine using below steps :- 1056 dd if=/dev/zero of=/root/myswapfile bs=1M count=1024 1057 ls -l /root/myswapfile 1058 chmod 600 /root/myswapfile 1059 mkswap /root/myswapfile 1060 swapon /root/myswapfile ... (1 Reply)
Discussion started by: apm
1 Replies

6. Emergency UNIX and Linux Support

Command to calculate space for all subdirs under a dir

du -hs command calculates the space for all the subdirs under a dir ...but it is very slow if the dir is huge....is there any quick way ...I am using Sun OS. Thanks, Ajay (19 Replies)
Discussion started by: ajaypatil_am
19 Replies

7. Fedora

Need to incrwase PHYSICAL VOLUME space on hard drive with free space on it

Hi, I run Fedora 17. I created a physical volume of 30GB on a disk with 60GB of space so there is 30GB of free space. On the physical volume, I created my volume group and logical volumes. I assigned all the space in the physical volume to my volume group. I need to add the 30GB of free space... (1 Reply)
Discussion started by: mojoman
1 Replies

8. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

9. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

10. Shell Programming and Scripting

Gawk --- produce the output in pattern space instead of END space

hi, I'm trying to calculate IP addresses and their respective calls to our apache Server. The standard format of the input is HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST... (2 Replies)
Discussion started by: busyboy
2 Replies
DBS-EDIT-PATCH(1)						Debian Build System						 DBS-EDIT-PATCH(1)

NAME
dbs-edit-patch - Edit a DBS patch SYNOPSIS
dbs-edit-patch [options] patch dbs-edit-patch -h|--help DESCRIPTION
dbs-edit-patch is script to generate or modify patches for Debian source-packages in DBS format. WARNING
dbs is deprecated, please switch to the `3.0 (quilt)' Debian source package format instead. See http://wiki.debian.org/Projects/Deb- Src3.0#FAQ for a short guide how to do it. OPTIONS
-h, --help Show summary of options. -t dir, --tmpdir=dir Directory for the temporary files, default is /tmp or if set $TMP. -s dir, --sourcedir=dir Top level directory of the debian-package source-tree, default is the present working directory. -P dir, --sourcepatchdir=dir Directory containing upstream patches. -T dir, --sourcetardir=dir Directory containing the upstream tarball. -p level, --strip=level Striplevel -p of patch (Option -p of diff(1)), accepted values are 0 and 1, default is 0. ENVIRONMENT VARIABLES
TMP Sets the directory for the temporary files, can be overridden with -t dir. debian/vars dbs-edit-patch will automatically use variables defined in the optional debian/vars file. When a file debian/vars.in exists and debian/vars either does not exist or is older than any of the following files: debian/vars.in, debian/changelog, debian/rules or debian/control, then dbs-edit-patch will try updating the vars file by running the following command make -f debian/rules -W debian/vars.in debian/vars EXAMPLES
Edit the 021_debian patch of Heimdal: ~/heimdal-0.3d> dbs-edit-patch -t/tmp 021_debian Extracting source heimdal-0.3d.tar.gz ... successful. Applying patch 001_replay ... successful. etc. Copying heimdal-0.3d to heimdal-0.3d-old ... successful. Applying patch 021_debian ... successful. Edit files under /tmp/021_debian/heimdal-0.3d as required, then put a short description into /tmp/021_debian/patch-description if desired, and finally execute /tmp/021_debian/dbs-update-patch to save the results. Technical note: dbs-edit-patch extracts all patches before 021_debian into /tmp/021_debian/heimdal-0.3d, copies the result to /tmp/021_debian/heimdal-0.3d-old, and applies the last patch 021_debian (if it exists). Also, it creates a shell script which will create the diff between the old and new directories: ~/heimdal-0.3d> ls -la /tmp/021_debian total 12 -rwxr-xr-x 1 bam users 112 Jan 31 13:31 dbs-update-patch* -rw-r--r-- 1 bam users 0 Jan 31 13:31 patch-description drwxr-xr-x 14 bam users 4096 Jan 31 13:31 heimdal-0.3d/ drwxr-xr-x 14 bam users 4096 Jan 31 13:31 heimdal-0.3d-old/ drwxr-xr-x 5 bam users 4096 Jan 31 13:31 .stampdir/ ~/heimdal-0.3d> cat /tmp/021_debian/dbs-update-patch #!/bin/sh -e cd "/tmp/021_debian" HOOK_DIR="/usr/src/heimdal/debian/dbs-hooks" test -d "$HOOK_DIR" && run-parts "$HOOK_DIR" --arg update-patch-prediff find -name "*.bak" -print0 | xargs -0 --no-run-if-empty rm find -name "*~" -print0 | xargs -0 --no-run-if-empty rm : > new_patch test ! -e patch-description || cp patch-description new_patch diff -ruN heimdal-0.3d-old heimdal-0.3d >> new_patch || test $? -eq 1 mv new_patch /usr/src/heimdal/debian/patches/021_debian test -d "$HOOK_DIR" && run-parts "$HOOK_DIR" --arg update-patch-postdiff SEE ALSO
diff(1), dbs(7), /usr/share/doc/dbs/ AUTHOR
DBS was written by Adam Heath, modified by Ben Collins, modified and packaged for Debian by Brian May. This manpage was generated by Andreas Metzler and modified by Robert Luberda. Debian February 15th, 2011 DBS-EDIT-PATCH(1)
All times are GMT -4. The time now is 03:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy