Need help converting df output to gigabytes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help converting df output to gigabytes
# 1  
Old 11-15-2012
Need help converting df output to gigabytes

I need some help converting the disk space values in kilobytes to gigabytes. I can't use df -h because the report has to be in megabytes for some disk space tracking software the customer is using.

I have been playing around with trying to assign variables I can use outside of awk so I can do the calculations, but am not having much luck.

Can someone help me with this code?


Code:
#!/bin/sh

dat1=`date '+%m/%d/%y'`

hst=`hostname`

df -k | sed -e /^Filesystem/d | awk -v OFS=',' -v dat="$dat1,$hst" ' {print dat,$1,$6,$3,$4 } '

The output right now looks something like this.

11/15/2012 hostname /dev/sda8 / 846516 4931376
11/15/2012 hostname /dev/sda9 /home 212488 1713428
11/15/2012 hostname /dev/sda7 /usr 3855572 5774300
11/15/2012 hostname /dev/sda6 /tmp 761336 8868536
11/15/2012 hostname /dev/sda5 /var 2063256 7566616
11/15/2012 hostname /dev/sda3 /opt 6649916 12617288
11/15/2012 hostname /dev/sda1 /boot 19031 76836

I was just thinking is there any easy way I can just divide by 1024 in the awk portion of the script? It looks like there is something I need to do to force the value to be numeric because the value is always 0.

Last edited by kuliksco; 11-15-2012 at 09:47 PM..
# 2  
Old 11-15-2012
How about this:

Code:
df -Pk | awk -v OFS=, -v dat="`date +%m/%d/%Y`,`hostname -s`" '!/^Filesystem/ { print dat,$1,$6,$3/1024,$4/1024}'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Help in converting

I have Excel file with the below three columns, i need your expertise in converting this to .csv file delimiter "|" Excel - Serial Number Serial Name Serial Brand 111 test sample 123 test2 sample1 134 ... (9 Replies)
Discussion started by: kiran_hp
9 Replies

2. UNIX for Dummies Questions & Answers

Converting txt output to rows and columns and send report via mail.

Hi All, I would like to send below output in a tabular column ( xml or excel ) and send a mail. vinay unix anil sql vamsee java request to suggest a solution. (1 Reply)
Discussion started by: Girish19
1 Replies

3. Ubuntu

Converting Impress output to DVD video

I have a need to convert 'Impress' presentations to DVD video format whilst retaining the original presentation in situ. Copying the individual slides and modifying size etc. in Gimp and then importing them into 'Openshot' is both long winded and the loss of quality is significant. Can anybody... (14 Replies)
Discussion started by: Royalist
14 Replies

4. Shell Programming and Scripting

Converting line output to column based output

Hi Guys, I am trying to convert a file which has a row based output to a column based output. My original file looks like this: 1 2 3 4 5 6 1 2 3 1 2 3 (8 Replies)
Discussion started by: npatwardhan
8 Replies

5. AIX

Converting Blocks to megabytes and gigabytes.

Sorry for the simple question. I am new to Unix and Unix AIX. I increased a file system the other day but cheated and used a conversion calculator. Could you good people tell me the best way to increase a file system that is in 512 byte blocks. Say the file system is 100mb and I wanted... (5 Replies)
Discussion started by: jfd7000
5 Replies

6. Shell Programming and Scripting

Converting to columnar output

Hi All, I need some help in script or awk to create a textfile. I have a directory where two subdirectories exists say A and B. Now I need to write a ".txt" file with well arranged(space wraped) three columns in it with the data as follows: 1st column:Serial number(which will increment... (4 Replies)
Discussion started by: Sreejith_VK
4 Replies

7. UNIX for Dummies Questions & Answers

Converting gettimeoftheday output to string

Hi .. is there a way i can retrieve the output of gettimeoftheday in a string (1 Reply)
Discussion started by: p_aishwarya
1 Replies

8. Shell Programming and Scripting

Converting \0 to a \n

Hi - I have seen some similar posts but I am a bit stumped here below is the first line of a 'od -c filename' command. I want to change the \0 to \n 0000000 l s \0 c d - \0 c d . . \0 l s I have tried a sed construct in a script......... sed... (2 Replies)
Discussion started by: ajcannon
2 Replies

9. SCO

Converting

I use Sco_Sv 3.2v5.0.5 with parellel conection using dump terminals and i want to convert them to desktop pc. Anybody knows what hardware and other thing that would be involved? (3 Replies)
Discussion started by: seeyou
3 Replies
Login or Register to Ask a Question