There is definatly a problem somewhere in my code..... i think as it doesnt seem to be behaving the way that it should.
things that should not be being logged are, and things that i am explicitly telling not to exist are existent..... and previous help 266197 while suggesting ideas that should have worked did not do anything other then try really hard to help. at this point i am beginning to wonder if it is Expect.pm 's loging function that is the problem and not my code.... but as an uber-novice i am enclined to blame myself due to shear likelyhood that i am totally not doing something correctly, as i do that alot.

here is my code

#!/usr/bin/perl -w use strict; use Expect; $|++; open STDERR, "/dev/null"; my $username="testuser"; my $password="password"; my $host="localhost"; my $timeout=5; my $exp = new Expect; $exp->log_file(undef); print "Content-type: text/html\n\n<html>"; telnet_login($username,$password,$host,\$exp); $exp->expect($timeout, ['ncorrect', sub { print "<center>ERROR:<br>Login Incorre +ct, check username or password</center>\n"; &html_stop; die; } ], [timeout => sub { $exp->send("/bin/sh\n"); $exp->send("/usr/bin/last -5 $username\n"); $exp->clear_accum(); $exp->log_file(\&formatoutput); $exp->send("/bin/cat /etc/passwd\n"); } ], ); $exp->soft_close(); sub formatoutput { my $input = shift; chomp($input); $input =~ tr/\r//; $input =~ s|\n|<br>\n|g; unless ($input =~ m!^(?:bin/sh|\$\s|/|\$)!) { print"${input}<p>\n"; } } sub telnet_login { my ($username, $password, $host, $exp) = @_; $$exp->raw_pty(1); #treat this terminal as a raw file $$exp->log_stdout(0); #do not show terminal output to STD Out $$exp->spawn("/usr/bin/telnet $host") || die "Cannot open telnet\n +"; $$exp->expect(7, ['ogin:', sub { $$exp->send("$username\n"); exp_conti +nue; } ], ['assword:', sub { $$exp->send("$password\n"); } ], [timeout => sub { die "<center>ERROR: <BR>A timeout h +ast occure d at login</center>\n"; } ], ); } </html>
here is expect's logging function from Expect.pm v1.15, im not sure if this will help at all but other then wasting space what harm can it do to post it?
sub log_file { my $self = shift; return(${*$self}{exp_Log_File}) if not @_; # we got no param, return filehandle my $file = shift; my $mode = shift || "a"; if (${*$self}{exp_Log_File} and ref(${*$self}{exp_Log_File}) ne 'C +ODE') { close(${*$self}{exp_Log_File}); ${*$self}{exp_Log_File} = undef; } return if (not $file); my $fh = $file; if (not ref($file)) { # it's a filename $fh = new IO::File $file, $mode or croak "Cannot open logfile $file: $!"; } if (ref($file) ne 'CODE') { croak "Given logfile doesn't have a 'print' method" if not $fh->can("print"); $fh->autoflush(1); # so logfile is up to date } ${*$self}{exp_Log_File} = $fh; }
here is my output, (please note it contains several differnt runs to show the differences in output i get when all i do is run it again, without changing any code at all) while the changes in times and ptys and loggin status make sense the changing of where newlines are and the addition of $'s occasionally has me confused
testuser pts/6 localhost Tue Jun 17 09:16 still logged in testuser pts/5 localhost Tue Jun 17 09:16 still logged in testuser pts/4 localhost Mon Jun 16 15:55 - 15:55 (00:00) testuser pts/4 localhost Mon Jun 16 15:53 - 15:53 (00:00) testuser pts/4 localhost Mon Jun 16 15:53 - 15:53 (00:00) root:x:0:1::/:/sbin/sh daemon:x:1:1::/: bin:x:2:2::/usr/bin: sys:x:3:3::/: adm:x:4:4:Admin:/var/adm: lp:x:71:8:Line Printer Admin:/usr/spool/lp: uucp:x:5:5:uucp Admin:/usr/lib/uucp: nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico listen:x:37:4:Network Admin:/usr/net/nls: nobody:x:60001:60001:Nobody:/: noaccess:x:60002:60002:No Access User:/: nobody4:x:65534:65534:SunOS 4.x Nobody:/: fast:x:204:1:FastTrack Server:/web:/bin/sh postfix:x:100:1:postfix:/dev/null:/bin/false vscan:x:1001:10:Amavis User:/usr/local/encap/amavis-perl-11:/bin/sh sshd:x:22000:22000:SSHD privsep User:/var/empty:/bin/false --------- testuser pts/5 localhost Tue Jun 17 09:17 still logged in testuser pts/6 localhost Tue Jun 17 09:16 - 09:17 (00:00) testuser pts/5 localhost Tue Jun 17 09:16 - 09:17 (00:00) testuser pts/4 localhost Mon Jun 16 15:55 - 15:55 (00:00) testuser pts/4 localhost Mon Jun 16 15:53 - 15:53 (00:00) root:x:0:1::/:/sbin/sh daemon:x:1:1::/: bin:x:2:2::/usr/bin: sys:x:3:3::/: adm:x:4:4:Admin:/var/adm: lp:x:71:8:Line Printer Admin:/usr/spool/lp: uucp:x:5:5:uucp Admin:/usr/lib/uucp: nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico listen:x:37:4:Network Admin:/usr/net/nls: nobody:x:60001:60001:Nobody:/: noaccess:x:60002:60002:No Access User:/: nobody4:x:65534:65534:SunOS 4.x Nobody:/: fast:x:204:1:FastTrack Server:/web:/bin/sh postfix:x:100:1:postfix:/dev/null:/bin/false vscan:x:1001:10:Amavis User:/usr/local/encap/amavis-perl-11:/bin/sh sshd:x:22000:22000:SSHD privsep User:/var/empty:/bin/false ------- testuser pts/5 localhost Tue Jun 17 09:18 still logged in testuser pts/5 localhost Tue Jun 17 09:17 - 09:18 (00:00) testuser pts/6 localhost Tue Jun 17 09:16 - 09:17 (00:00) testuser pts/5 localhost Tue Jun 17 09:16 - 09:17 (00:00) testuser pts/4 localhost Mon Jun 16 15:55 - 15:55 (00:00) root:x:0:1::/:/sbin/sh daemon:x:1:1::/: bin:x:2:2::/usr/bin: sys:x:3:3::/: adm:x:4:4:Admin:/var/adm: lp:x:71:8:Line Printer Admin:/usr/spool/lp: uucp:x:5:5:uucp Admin:/usr/lib/uucp: nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico listen:x:37:4:Network Admin:/usr/net/nls: nobody:x:60001:60001:Nobody:/: noaccess:x:60002:60002:No Access User:/: nobody4:x:65534:65534:SunOS 4.x Nobody:/: fast:x:204:1:FastTrack Server:/web:/bin/sh postfix:x:100:1:postfix:/dev/null:/bin/false vscan:x:1001:10:Amavis User:/usr/local/encap/amavis-perl-11:/bin/sh sshd:x:22000:22000:SSHD privsep User:/var/empty:/bin/false ----- testuser pts/6 localhost Tue Jun 17 09:19 still logged in testuser pts/5 localhost Tue Jun 17 09:19 still logged in testuser pts/5 localhost Tue Jun 17 09:18 - 09:19 (00:00) testuser pts/5 localhost Tue Jun 17 09:17 - 09:18 (00:00) testuser pts/6 localhost Tue Jun 17 09:16 - 09:17 (00:00) $ root:x:0:1::/:/sbin/sh daemon:x:1:1::/: bin:x:2:2::/usr/bin: sys:x:3:3::/: adm:x:4:4:Admin:/var/adm: lp:x:71:8:Line Printer Admin:/usr/spool/lp: uucp:x:5:5:uucp Admin:/usr/lib/uucp: nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico listen:x:37:4:Network Admin:/usr/net/nls: nobody:x:60001:60001:Nobody:/: noaccess:x:60002:60002:No Access User:/: nobody4:x:65534:65534:SunOS 4.x Nobody:/: fast:x:204:1:FastTrack Server:/web:/bin/sh postfix:x:100:1:postfix:/dev/null:/bin/false vscan:x:1001:10:Amavis User:/usr/local/encap/amavis-perl-11:/bin/sh sshd:x:22000:22000:SSHD privsep User:/var/empty:/bin/false ------ testuser pts/5 localhost Tue Jun 17 09:20 still logged in testuser pts/6 localhost Tue Jun 17 09:20 - 09:20 (00:00) testuser pts/8 localhost Tue Jun 17 09:20 - 09:20 (00:00) testuser pts/5 localhost Tue Jun 17 09:20 - 09:20 (00:00) testuser pts/7 localhost Tue Jun 17 09:19 - 09:20 (00:00) root:x:0:1::/:/sbin/sh daemon:x:1:1::/: bin:x:2:2::/usr/bin: sys:x:3:3::/: adm:x:4:4:Admin:/var/adm: lp:x:71:8:Line Printer Admin:/usr/spool/lp: uucp:x:5:5:uucp Admin:/usr/lib/uucp: nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico listen:x:37:4:Network Admin:/usr/net/nls: nobody:x:60001:60001:Nobody:/: noaccess:x:60002:60002:No Access User:/: nobody4:x:65534:65534:SunOS 4.x Nobody:/: fast:x:204:1:FastTrack Server:/web:/bin/sh postfix:x:100:1:postfix:/dev/null:/bin/false vscan:x:1001:10:Amavis User:/usr/local/encap/amavis-perl-11:/bin/sh sshd:x:22000:22000:SSHD privsep User:/var/empty:/bin/false ----- testuser pts/5 localhost Tue Jun 17 09:29 still logged in testuser pts/5 localhost Tue Jun 17 09:28 - 09:29 (00:00) testuser pts/5 localhost Tue Jun 17 09:28 - 09:28 (00:00) testuser pts/5 localhost Tue Jun 17 09:27 - 09:27 (00:00) testuser pts/5 localhost Tue Jun 17 09:27 - 09:27 (00:00) root:x:0:1::/:/sbin/sh daemon:x:1:1::/: bin:x:2:2::/usr/bin: sys:x:3:3::/: adm:x:4:4:Admin:/var/adm: lp:x:71:8:Line Printer Admin:/usr/spool/lp: uucp:x:5:5:uucp Admin:/usr/lib/uucp: nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico listen:x:37:4:Network Admin:/usr/net/nls: nobody:x:60001:60001:Nobody:/: noaccess:x:60002:60002:No Access User:/: nobody4:x:65534:65534:SunOS 4.x Nobody:/: fast:x:204:1:FastTrack Server:/web:/bin/sh postfix:x:100:1:postfix:/dev/null:/bin/false vscan:x:1001:10:Amavis User:/usr/local/encap/amavis-perl-11:/bin/sh sshd:x:22000:22000:SSHD privsep User:/var/empty:/bin/false $
while i do have a workaround for removing the echoing of bin/sh to the screen even that was showing up in there. and ultimatly this is going to be deployed across a few different platforms (irix, solaris, linux) and as a result i cannot count on knowing what the prompt (the $ in solaris which is my current test enviroment) will be for parsing out and in general i should be having to do that, should i? i mean if the logging was working the way i thought i was telling it to then that output should be sent nowhere.
really apprecate the time spent looking at this, and would like to thank you in advance for anyhelp that you supply.

In reply to insconsistency and things that should not be by jcpunk

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.