[Bug 108497] Re: The sysinfo script in Konvesation in Feisty does not display the diskspace anymore
gnomon
bzanin at gmail.com
Tue Jun 3 19:00:54 UTC 2008
There are actually two problems this awk script: one is the obvious
problem of using the gawk-specific '**' to perform exponentiation rather
than the awk standard '^', and the other is an assumption that every
line of df output corresponds to a single record. Unfortunately this is
not the case: when device names are very line, df will helpfully break
records across multiple lines, like so:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/sda4_crypt
450180024 395426136 32066144 93% /
varrun 517168 192 516976 1% /var/run
varlock 517168 0 517168 0% /var/lock
udev 517168 96 517072 1% /dev
devshm 517168 0 517168 0% /dev/shm
lrm 517168 38176 478992 8% /lib/modules/2.6.24-17-generic/volatile
/dev/sdc2 972180 54892 868292 6% /boot
/dev/mapper/sdb1_crypt
307663284 218735800 73299080 75% /media/sdb1
/dev/mapper/sdc1_crypt
153834336 49176656 96843292 34% /media/sdc1
/dev/mapper/sdd1_crypt
484534988 269085988 191029828 59% /media/sdd1
In this case, we need slightly more sophisticated processing:
HDD=$(df -l | awk 'BEGIN {
# In the output of df -l, the first field is the device name...
TOT = 2 # ...the second field is the total size...
USE = 3 # ...and the third field is the amount used.
BLK = 1024^2
# It is a small thing, but why recalculate the value of a block
# on every line rather than just doing it once? Keeping this
# definition up front makes it easier to modify in the future,
# too: the script currently assumes 1-kilobyte blocks, but
# that need not always be the case.
}
($1 ~ /^\/dev\// && NF == 1) {
# we handle the case of lines produced by df which feature only
# the device name, which is too long to fit into its column display,
# by grabbing the device name, forcing a new line to be read,
# then prepending the saved device name onto the new line.
# Then every line that we care about is in the same format. The
# next rule will then work in all cases.
dev = $1
getline
$0 = dev " " $0
}
($1 ~ /^\/dev\//) {
use += $USE / BLK
tot += $TOT / BLK
}
END {
printf "HD: %s / %s GB\n", use, tot
}')
--
The sysinfo script in Konvesation in Feisty does not display the diskspace anymore
https://bugs.launchpad.net/bugs/108497
You received this bug notification because you are a member of Kubuntu
Team, which is subscribed to konversation in ubuntu.
More information about the kubuntu-bugs
mailing list