I am trying to write php script which does some shell functions like reporting. So i am starting with diskusage report
I want in following format
drive path ------------total-size --------free-space
Nothing else
My script is
$output = shell_exec('df -h -T');
echo "<pre>$output</pre>";
and its ouput is like below
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda6 ext3 92G 6.6G 81G 8% /
none devtmpfs 3.9G 216K 3.9G 1% /dev
none tmpfs 4.0G 176K 4.0G 1% /dev/shm
none tmpfs 4.0G 1.1M 4.0G 1% /var/run
none tmpfs 4.0G 0 4.0G 0% /var/lock
none tmpfs 4.0G 0 4.0G 0% /lib/init/rw
/dev/sdb1 ext3 459G 232G 204G 54% /media/Server
/dev/sdb2 fuseblk 466G 254G 212G 55% /media/BACKUPS
/dev/sda5 fuseblk 738G 243G 495G 33% /media/virtual_machines
How can i convert that ouput into my forn\matted output
Something like this:
Should get you going anyway
Why not use PHP's
disk_total_space()
anddisk_free_space()
functions instead? Otherwise, one way is you could parse $output into a multidimensional array using preg_ functions, convert 'g', 'k', 'm' characters to numbers, and total the column. Alternatively, if the column space is a single tab character or a set number of spaces, you could justexplode()
each line into a multidimensional array.