Hello monks, I have a bunch of old freebsd machines. I'm tring to send them somme commands with Net::Appliance:session module and get the results. I've custom phasebook called FreeBSD411. That's the code:
my $s = Net::Appliance::Session->new({ personality => "FreeBSD411", add_library => "./PhaseBooks", transport => 'SSH', host => $host, #privileged_paging => 1, # only if using ASA/PIX OS 7+ # and there are other behaviour options, +see below connect_options => { opts => [ '-p', '22', # connect to non-standard port on +remote host #'-o', 'CheckHostIP=no', # don't check host IP in known_h +osts file ], }, log_config => { dispatchers => ['screen','file'], screen => { class => 'Log::Dispatch::Screen', min_level => 'warning', }, file => { class => 'Log::Dispatch::File', min_level => 'debug', filename => '/var/log/myapp.log', mode => 'append', format => '[%d] %m', }, }, }); $s->set_global_log_at('debug'); try { my @result = shift; my @cmds = ('whoami','uname -a','df -h'); $s->connect({ username => $user, password => $pass, privileged_pas +sword => $su_pass}); $s->disable_paging(1); $s->begin_privileged({$su_pass}); ## I don't know how to call t +his ;) or Doesn't work ? push @result, $s->cmd("$cmds[0]"); #push @result, $s->cmd("$cmds[1]"); #push @result, $s->cmd("$cmds[2]"); $s->end_privileged; print "Host: $host \"@cmds\": @result \n"; } catch { warn "failed to execute command: $_"; } finally { $s->close; };
The custom Phasebook - FreeBSD411
prompt user match /[Uu]sername: $/ prompt pass match /[Pp]assword:\s+$/ prompt passsu match /[Pp]assword:$/ prompt generic03 match /\/]\$\s+$/ prompt generic01 match /\/\]\$\s+$/ prompt generic02 match /from$/ prompt generic match /\s+\/]\$$/ prompt privileged # match /^root@.+#\s+$/ match /^\[root@.+\~\]\#\s+$/ macro begin_privileged send su - match passsu or privileged macro end_privileged send exit match generic macro disconnect send logout macro paging send '' # send terminal length %s

My problems : I didn't succeed to disable paging (disable_paging). I didn't succeed to become root with "su -" and execute somme comands ...

Log

...... [ 0.589068] di queueing data for send: "" [ 0.589289] tr callback received for match [ 0.600092] du SEEN: [user1@freebsd411 /]$ [ 0.600355] tr output matched (?-xism:\s+\/]\$$), storing and retur +ning [ 0.600926] pr output matching prompt was "[user1@freebsd411 /]$" [ 0.601122] pr setting new prompt to (?-xism:\s+\/]\$$) [ 0.601267] pr prompt has been set to (?-xism:\s+\/]\$$) [ 0.601403] di trimmed command response: Odd number of elements in anonymous hash at ./send-cmds.pl line 58. [ 0.602153] en running macro begin_privileged [ 0.602440] en executing actions [ 0.602699] en dispatching to execute method [ 0.603191] tr callback received for send [ 0.603317] di queueing data for send: "su -" [ 0.603535] tr callback received for match [ 0.620060] du SEEN: Password: [ 0.620492] tr output matched (?-xism:[Pp]assword:$), storing and r +eturning [ 0.622734] pr output matching prompt was "Password:" [ 0.622947] pr setting new prompt to (?-xism:[Pp]assword:$) [ 0.623088] pr prompt has been set to (?-xism:[Pp]assword:$) [ 0.623219] di trimmed command response: failed to execute command: should be in privileged mode but prompt doe +s not match at /Volumes/lala/Ports/lib/perl5/site_perl/5.12.4/Net/App +liance/Session/Engine.pm line 110. [ 0.624138] en running macro paging [ 0.624271] en macro params are: 24 [ 0.624580] en executing actions [ 0.624828] en dispatching to execute method [ 0.625317] tr callback received for send [ 0.625444] di queueing data for send: "" [ 0.625665] tr callback received for match [ 0.640885] du SEEN: Sorry [user1@freebsd411 /]$ ..............................
at line 58 :
$s->begin_privileged({$su_pass}); ## I don't know how to call/use + this ;) or Doesn't work ?
and into the module Engine.pm we've function begin_privileged:
110 $self->prompt_looks_like('privileged') 111 or die 'should be in privileged mode but prompt does not ma +tch'; 112 $self->in_privileged_mode(1);

In reply to Net::Appliance::Session, Disable paging & send commands after "su" ? by zen0

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.