#!/usr/bin/perl use CGI ':standard'; use strict; use warnings; use GD::Graph::pie; my $cmd_1 = "sudo df -h |grep /var |awk '{print \$2}' | sed -e 's/.\$//'"; my $cmd_2 = "sudo df -h |grep /var |awk '{print \$3}' | sed -e 's/.\$//'"; my $result_used = qx/ $cmd_1 /; #$result_used shows 1.4 my $result_free = qx/ $cmd_2 /; #$result_free shows 85 # Both the arrays should same number of entries. my @data = (['Used', 'Free'], [$result_used, $result_free]); my $mygraph = GD::Graph::pie->new(300, 300); $mygraph->set( title => '/var Partition, Size in GB', '3d' => 0, #'3d' => 1, ) or warn $mygraph->error; $mygraph->set_value_font(GD::gdMediumBoldFont); my $myimage = $mygraph->plot(\@data) or die $mygraph->error; print "Content-type: image/png\n\n"; print $myimage->png;