Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Ok, it's been a while since I've been this stumped on a Perl question and resorted to asking for help.

Ultimately, what I'm trying to accomplish here is to get information on any given remote file. I have access to the remote system via ssh and know the file's full path: call that $remotefile

The approach I was thinking of using is like so:

use Net::SSH::Perl; my $ssh = Net::SSH::Perl->new($remotehost); $ssh->login($remoteuser, $remotepassword); my($stdout, $stderr, $exit) = $ssh->cmd(qq[ls -l $remotefile]); # Then parse the info I want from $stdout with an easy regex

But I can't rule out the possibility that the remote filename might contain shell metacharacters.

My immediate thought was, "No problem, I'm sure the CPAN has six different modules for escaping shell metacharacters," but all I seem to be able to find is modules that appear to be intended for escaping strings in program source code (notably, String::Escape) or undoing said escaping (Encode::Escape for instance). To the best of my knowledge, those probably won't do entirely the right thing (e.g., with spaces). Am I correct in assuming that I need something different?

The characteristics of the remote system are known, and are essentially the same as the local system, although they get updates at different times. (Both systems are Debian.)

Thoughts? Other approaches?

We're working on a multi-year set of freely redistributable Vacation Bible School materials.

In reply to Getting information about a remote file via SSH: how to escape the filename by jonadab

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-11-28 18:58 GMT
Find Nodes?
    Voting Booth?