#!/usr/bin/perl use warnings; use strict; use Time::Local; my $kMaxLine = 70; #Will hold the command line data from the execution of module "add_userDefined" (my $module_cmd = "$0 @ARGV";) #But for now hard-code in an example. appendToFile( '/mrtg/mrtgwww/cfg/devices/Tests/Router-Memory_and_Storage.cfg', './add_userDefined --cfg=Router-Memory_and_Storage.cfg --host-template=In-Progress/Memory-and-Storage.htp --if-template=In-Progress/Memory.template --ip=10.10.10.10', ); sub appendToFile { my ($cfgFileName, $module_cmd) = @_; #Get ONLY the Month and the Year my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(); my %months = ( 0 => 'January', 1 => 'Feburary', 2 => 'March', 3 => 'April', 4 => 'May', 5 => 'June', 6 => 'July', 7 => 'August', 8 => 'September', 9 => 'October', 10 => 'November', 11 => 'December' ); $year = 1900 + $year; my $month_year = "$months{ $mon } $mday, $year"; my $cfgmaker_cmd; my $wholeFile; #open my $dataIn, '<', $cfgFileName or die "Error opening $cfgFileName: $!\n"; while (my $line = ) { next if $line =~ /^# Created by/i; if ($line =~ /\/jwpmrtg\/bin\/cfgmaker/i) { chomp($line); $cfgmaker_cmd .= $line; } else { $wholeFile .= $line; } } #close $dataIn; $_ = wrapLine($_) for $module_cmd, $cfgmaker_cmd; my $sep = '#' x $kMaxLine; my $comment .= <## ###################################################################### ## Date: Feburary 8, 2012 ## Module CMD: ./add_userDefined --cfg=Router-Memory_and_Storage.cfg ## --host-template=In-Progress/Memory-and-Storage.htp ## --if-template=In-Progress/Memory.template ## cfgmaker CMD: ######################################################################