The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 03:31 PM
Shell Script: want to insert values in database when update script runs ring Shell Programming and Scripting 1 10-25-2007 04:06 AM
here document to automate perl script that call script hogger84 Shell Programming and Scripting 3 10-22-2007 11:15 AM
returning to the parent shell after invoking a script within a script gurukottur Shell Programming and Scripting 5 09-26-2006 08:05 AM
return valuse from child script to parent script borncrazy Shell Programming and Scripting 1 08-20-2004 04:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-07-2008
oduth oduth is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 8
Awk script

Hi all,

I can't see some of file systems capacity output with file system name using below script:

here is the df output:

Code:
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda3             15116868  11890900   2458064  83% /
/dev/sda1               101086     13517     82350  15% /boot
none                  32435708         0  32435708   0% /dev/shm
/dev/mapper/ffderora-gghlvora
                      28092588   5301140  21364404  20% /oracle
/dev/sdi1            114222112 107657120   6564992  95% /orad2
/dev/sdh1            228444256 215828000  12616256  95% /orad9
/dev/sdj1            228444256 215594592  12849664  95% /orad10
/dev/sdk1            228444256 215086688  13357568  95% /orad11
/dev/sdl1            228444256 172073280  56370976  76% /orad12
/dev/sdm1            228444256 209843648  18600608  92% /orad1
/dev/mapper/ffderora-gghlvora
                     280995708 195028872  71696128  74% /rads01

Here is my script:

Code:
df -k | grep -v /dev/shm | grep -v cdrom | awk '{print $6,$5}' | tr -d \%

and its output:


Code:
/ 85
/boot 15

/oracle
/orad2 95
/orad9 95
/orad10 95
/orad11 95
/orad12 90
/orad1 92

/rads01

As you can see above output, /oracle and /rads01 file-systems have no capacity output since they have one more line (double-line)

how can i fix it?

Regards,

Last edited by Yogesh Sawant; 04-07-2008 at 05:00 AM.. Reason: added code tags
  #2 (permalink)  
Old 04-07-2008
oduth oduth is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 8
same problem occurs with this:
df -k | awk '{print $6 $5}'
  #3 (permalink)  
Old 04-07-2008
oduth oduth is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 8
df -k | grep -v /dev/shm | grep -v /dev/cdrom | awk '{print $5,$4}'

output :
83% 2455472
15% 82350

/oracle 20%
95% 6564992
95% 12616256
95% 12849664
95% 13357568
76% 56370976
92% 18600608

/rads01 74%
  #4 (permalink)  
Old 04-07-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,346
Try:


Code:
awk 'NF>1&&NR>1{sub("%","");print $NF, $(NF-1)}'

Regards
  #5 (permalink)  
Old 04-07-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
The output for oracle and rads01 is splitted over two lines.
So for this filesystems, the Use% fiels is 4, not 5.

Try and adapt the awk command :

Code:
df -k | \
awk '
   ! ( /\/dev\/shm/ || /cdrom/ ) {
      sub(/%/, "");
      Use = (NF == 6 ? 5 : 4)
      print $(Use+1),$Use
   }  '

Jean-Pierre.
  #6 (permalink)  
Old 04-07-2008
oduth oduth is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 8
Franklin52 & aigles

Both of them work and you're great!!

Thank you so much!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0