Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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


In reply to Router Backup.pl failing (operator error no doubt) by rmagin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (15)
    As of 2014-09-02 19:16 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (29 votes), past polls