I’ve done this a few times setting up MRTG and always get stuck when trying to use custom scripts.

The caveat is when you target a custom script the notation is:

Target[localhost.mem]: `/etc/mrtg/scripts/mem.pl`

or something along those lines, the caveat is that the quotes are not a ‘ but a ` ( the character at the top left of the keyboard)   this took me a little while to figure it out.

The perl script I am using is:


$machine = `/bin/hostname`;
$mem = `/usr/bin/free | grep Mem`;
$uptime = `/usr/bin/uptime`;

if ($mem =~ /^Mem:\s*(\d*)\s*(\d*)\s*(\d*)/) {
 $tot = $1;
 $used = $2;
 $free = $3;

if ($uptime =~ /up (.*),  \d* users?,/) {
 $up = $1;
print "$used\n";
print "$free\n";
print "$up\n";
print "$machine\n";

I took this from another site.. I will probablly write my shell scripts in PHP, they are just as easy , and powerful