### This is the the problem area ### @vacation_str=$telnet->cmd("$SED s/\$SUBJECT/SUBJECT/g /home/$usern +ame/.vacation.msg"); ###

I'd guess that the problem is that you need to add an extra pair of \ to your sed command in order to escape SUBJECT properly:

### This is the the problem area ### @vacation_str=$telnet->cmd("$SED s/\\\$SUBJECT/SUBJECT/g /home/$use +rname/.vacation.msg"); ###

As is, "\$SUBJECT" will send "$SUBJECT" to the shell that you're talking to; that shell will try to expand $SUBJECT. Since this is actually text within the file you're munging, you need to make the shell see \$SUBJECT. (I'm guessing here but this seems about right.)

Another way of doing it would be to cut sed out of the loop altogether:

@vacation = map { s/\$SUBJECT/SUBJECT/g } $telnet->cmd("cat ~$username/.vacation.msg");

If that doesn't fix it, then the problem might not be the shell interpreting SUBJECT - perhaps the .vacation.msg file you're looking at has a sequence of characters in it that match your Net::Telnet object's prompt() string. You may need to try briefly undefining prompt() within your object, do your cat/sed/whatever, then re-define prompt().

Gosh, I'm just full of ideas. In some places, your code refers to $$telnet, and in others, it refers to $telnet. This might be causing your cmd() some grief. Try tossing a 'use strict; use warnings;' at the top of your code to see what complains :)

When automating Net::Telnet connections to other machines, I've found that I can get away with a very limited range of commands at the remote machine, particularly for file manipulations such as the one you're doing. /bin/echo and /bin/ls can be used to check whether files and directories exist; /bin/cat returns file contents to your program, so you can do whatever complex greps and seds on them using Perl's regexes.

Good luck on your project, sounds like a fun one.

blyman
setenv EXINIT 'set noai ts=2'

In reply to Re: Net::Telnet, cmd, and sed by belden
in thread 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.