Good morning,
I am still suffering with problems with the Net::Telnet module. Basically, I need to telnet into a machine, read in the contents of the .vacation.msg file, and, without changing the actual .vacation.msg file, return to the perl script the vacation message with all occurances of '$SUBJECT' replaced with 'SUBJECT'. The relavant code is as follows:
#!/usr/bin/perl my $SED = "/bin/sed"; my $username = "user1"; my $password = "password"; my $host = "localhost"; &start_login; sub start_login { my $telnet = new Net::Telnet( -host => $hostname, -telnetmode => ''); telnet_login($username,$password,$host,\$telnet); ### This is the the problem area ### @vacation_str=$telnet->cmd("$SED s/\$SUBJECT/SUBJECT/g /home/$usern +ame/.vacation.msg"); ### telnet_close(\$telnet); } sub telnet_login { use Net::Telnet; my ($username, $password, $host, $telnet) = @_; my $error_msg = "Incorrect username or password, please try again" +; my $error_type = "ERROR"; $$telnet = new Net::Telnet ('Timeout'=>'7', 'Prompt'=> '/.*([\$#\%>~]|\\\[\\e\[0m\ +\\] \[0m)\s?/' ); $$telnet->open(Host=>$host); $$telnet->login($username,$password); }
I applogize for posting a similar post previously. Two people responded with some very good ideas that I am stil working with. Yet, I am still unable to make headway. The above code does not return to the variable @vacation_str what I expect. If I simply run the above 'sed' command in bash, it returns exactly what I am looking for (a vacation message string with all of the '$'s stripped from it). However, Using the Net::Telnet 'cmd' method to send the above command 'sed s/\$SUBJECT/SUBJECT/g /home/$username/.vacation.msg', only the first line of the vacation message shows up. Dispite all the approaches I have tried, I have not found one that returns the full contents of the .vacation.msg file when the file contains a $. My best guess is that I am not escaping something in the 'sed' commnad correctly, though I have tried fruitlessly to modify the expression so that it will work. If anyone has any ideas or resources, I would be very open to what you have to say. Thanks for your time,
Joe

In reply to Net::Telnet, cmd, and sed by JoeJaz

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.