alas monks I am totally confused by this one, it appears that Expect's logging functions do not opperate in a standard way. If I might prevail upon you to examine the code here and determine why the output here is as it is, logging things to places it I explicitly told it NOT to log to.
Here is the program I am testing this with
#!/usr/bin/perl -w use strict; use Expect; |++; print "Content-type: text/html\n\n<html>"; my $username="testuser"; my $password="password"; my $host="localhost"; my $timeout=7; my $exp = new Expect; # create our important expet object 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->log_file("/dev/null"); $exp->send("/bin/sh\n"); $exp->send("/usr/bin/last -10 $username\n"); $exp->log_file(\&formatoutput); $exp->send("/bin/cat /etc/passwd\n"); } ], ); $exp->soft_close(); #gentially close this object, it has been nice to +us we hope sub formatoutput { my $input = shift; chomp($input); $input =~ tr/\r//; $input =~ s/\n/<br>/g; unless( ($input eq "\$ ") || ($input eq "\/") || ($input eq "bin/sh") || ($input eq "bin\/sh") || ($input eq "/bin/sh") || ($input eq "/bin/sh ") ) # things not to print go in this ^ statement { print"<b>${input}</b><p>\n"; } } sub telnet_login { my ($username, $password, $host, $exp) = @_; my $TELNET = "/usr/bin/telnet"; my $timeout = 7; $$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("$TELNET $host") || die "Cannot open telnet\n"; # try + to startup $TELNET $$exp->expect($timeout, ['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 occured at login</center>\n"; } ], ); } </html>
as you can tell from my code I am sending everything up until the cat'ing of /etc/passwd to /dev/null but that doesnt stop my output from looking like this:
bin/sh testuser pts/5 localhost Mon Jun 16 09:16 still logged in testuser pts/5 localhost Mon Jun 16 09:14 - 09:15 (00:00) testuser pts/5 localhost Mon Jun 16 09:09 - 09:09 (00:00) testuser pts/5 localhost Mon Jun 16 09:08 - 09:08 (00:00) testuser pts/6 localhost Mon Jun 16 09:07 - 09:08 (00:00) testuser pts/5 localhost Mon Jun 16 09:07 - 09:07 (00:00) testuser pts/5 testuser Fri Jun 13 15:54 - 15:55 (00:00) testuser pts/5 testuser Fri Jun 13 15:53 - 15:54 (00:00) testuser pts/5 testuser Fri Jun 13 15:52 - 15:53 (00:00) testuser pts/5 testuser Fri Jun 13 15:52 - 15:52 (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
any thoughts as to why I get both the bin/sh and the last sent to my output?

In reply to phantom log from hell? 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.