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

I need enlightenment with Net::Telnet.

I am attempting to log into another machine and do a tail of a file and have that output of that tail go to an html page. The problem is that the filename that I am tailing via telnet is a variable:

Filename:  /data/project/cann/log/cannedfile.$${bus_dt}

The cmd to telnet is
$t1->cmd( $command );

$command="tail -25 /data/project/cann/log/cannedfile.$${bus_dt}";

$${bus_dt} is valid global variable on that machine and it should evaluate just fine (at least it does from the command line on that box. The problem is that telnet is converting the $$ to a number 8560721 (something like that).

In other words, the error message I get is:
file not found: /data/project/cann/log/cannedfile.8560721.{bus_dt}

Please let me know if I provided enough information.

Thank you in advance,

Louis

update (broquaint): removed <table> tags and added some <code> tags

Replies are listed 'Best First'.
Re: Perl Telnet weirdness
by insensate (Hermit) on Nov 11, 2002 at 16:04 UTC
    That's because $$ is the special variable representing the program's pid...try putting the command in single quotes instead...that will supress variable interpolation.

      I modified my code as such:

      my @lines;
      my $command;
      $command = "tail -$num $logfile";
      @lines = ($t1->cmd('$command'));
      print "@lines";

      The tail command does not seem to be executed. Nothing is printed to the screen. Any advice?

        Remember that single quotes supress variable interpolation...so '$command' will not be interpreted as it's contents...try
        $t1->cmd($command);
Re: Perl Telnet weirdness
by pg (Canon) on Nov 11, 2002 at 16:48 UTC
    That's the tricky opart about Perl, there are lots of predefined variables. $$ is the process id. Try this:
    use English; print $PPROCESS_ID, "\n"; print $PID, "\n"; print $$, "\n";
    Those three prints yield the same result.
A funny way to demo $$
by pg (Canon) on Nov 11, 2002 at 19:09 UTC
    use strict; sub who_killed_hummingbird { print "Oho, I killed myself!"; } $SIG{INT} = \who_killed_hummingbird; kill 9, $$;
      Or perhaps more safely
      $SIG{TERM} = sub { print "my bad\n"; exit 0; }; kill TERM, $$; __output__ my bad
      As (at least on my linux system) 9 corresponds to the KILL signal which you can't trap.
      HTH

      _________
      broquaint