http://www.perlmonks.org?node_id=1018799

rmagin has asked for the wisdom of the Perl Monks concerning the following question:

Hello oh powerful Monks I need your help, I keep getting an error on my backup script but everything looks perfect.

I am launching a test by typing: perl -c backup.pl

The error message is:

syntax error at backup.pl line 44, near "$status=~/.+ = "(.+)".*$" (Might be a runaway multi-line $$ string starting on line 43) backup.pl had compilation errors.

I am using a script found here: http://www.fengnet.com/book/Cisco.IOS.Cookbook.2nd/I_0596527225_CHP_1_SECT_19.html#I9617__ExampleLabel__Example_1_4

Is it a typo from this script or should i attempt retyping entire script by hand in case there is a parse somewhere else?

Here is the code from the page

#!/usr/local/bin/perl # # backup.pl -- a script to automatically backup a list of # router configuraton files on a nightly basis. # # # Set behavior $workingdir="/home/cisco/bkup"; $snmprw="ORARW"; $ipaddress="172.25.1.1"; $days="30"; # # $rtrlist="$workingdir/RTR_LIST"; $storage="$workingdir/storage"; $latest="$storage/LATEST"; $prev="$storage/PREV"; if (! -d $storage) {mkdir ($storage, 0755)}; if (! -d $prev) {mkdir ($prev, 0755)}; if (! -d $latest) {mkdir ($latest, 0755)}; ($sec, $min, $hr, $mday, $mon, $year, @etc) = localtime(time); $mon++; $year=$year+1900; $today1=sprintf("%.4d_%.2d_%.2d", $year, $mon, $mday); $today="$storage/$today1"; system("cp -p $latest/* $prev/"); unlink <$latest/*>; mkdir ($today, 0755); open (RTR, "$rtrlist") || die "Can't open $rtrlist file"; open (LOG, ">$workingdir/RESULT") || die "Can't open $workingdir/RESUL +T file"; print LOG "Router Configuration Backup Report for $year/$mon/$mday\n"; print LOG "======================================================\n"; print LOG "Device Name Status\n"; print LOG "======================================================\n"; while (<RTR>) { chomp($rtr="$_"); $oid=".1.3.6.1.4.1.9.2.1.55.$ipaddress"; $snmpset ="/usr/local/bin/snmpset -v1 -c $snmprw -t60 -r2 $rtr"; $rtrfile="/tftpboot/$rtr.cfg"; unlink $rtrfile; open (CFG, ">$rtrfile"); print CFG " ";close CFG; chmod 0666, $rtrfile; chop ($status=\Q$snmpset $oid s $rtr.cfg\Q); $status=~/.+ = "(.+)".*$/; if($1 eq "$rtr.cfg") { if( -z "$rtrfile" ) { $result="not ok (File empty)"; unlink $rtrfile; } else { $result="ok"; chmod 0444, $rtrfile; system("mv $rtrfile $latest"); } } else { $result="not ok"; unlink $rtrfile; } printf LOG ("%-28s %-28s\n", $rtr,$result); } system ("cp -p $latest/*cfg $today"); $time=$days*86400; print "$time\n"; ($sec, $min, $hr, $mday, $mon, $year, @etc) = localtime(time-$time); $mon++; $year=$year+1900; $rmdir=sprintf("%s/%.4d_%.2d_%.2d",$configs, $year, $mon, $mday); system ("rm -r -f $storage/$rmdir");

Thank you for being here Guru's...Rmagin