zeewagon zeewagon - 1 year ago 86
Bash Question

How to export daily disk space usage?

I am new to scripting.

Is it possible to export the disk space usage of a linux server to an excel shell(.csv) sheet daily ?
If so, what will be the scripting for that?

Answer Source

Use awk to parse df result:

Assuming ; is your csv separator, then:

df -h | awk 'FNR == 2 {print $2";"$3";"$4}'



In a full script with the date:


SIZES=`df -h | awk -v SEP="$SEPARATOR" 'FNR == 2 {print SEP$2SEP$3SEP$4}'`
echo `date +%Z-%Y-%m-%d_%H-%M-%S`"$SIZES" >> test.csv
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download