using the system command with "rcp and rsh"

Posted on 2006-05-26
Last Modified: 2012-06-27
I have a script which I am trying to call from a Browser. I want to use "rsh" and "rcp" using a system command to access data on another server. Below is my script. Both the rsh and rcp command work fine when run in the command line.


use warnings;
use CGI;

print "Content-type: text/html\n\n";
print "Hello World\n";

system(`rsh -l user 'ls -l' > test.txt`);
system(`rcp file.localcopy`);

The "Hello World" string gets printed to my Browser.
The test.txt file gets created locally but is EMPTY
The rcp command does not return anything.

If I run the rsh command on my CLI I get the test.txt file created with the directory contents from teh ls -l command
If I run the rcp command in the CLI I get the file transferred.

Simply when I trancfer the commands to teh script they stop working!!!!

Any thoughts, comments will be greatly appreciated.

Question by:Troyh
    LVL 6

    Accepted Solution

    Browsers usually run under a user with very low permissions for security reasons.  I'd guess that either you do not have a path to the command in your browsers environment so it can't find the commands or the user the browser is runnig under does not have permission to execute those commnands.

    The first is easiest to resolve.  Just put the path to the commands in the system call:

    system(`/path/to/rsh -l user 'ls -l' > test.txt`);
    system(`/path/to/rcp file.localcopy`);

    If that doesn't work then you have a permission problem.  But I'm inclined to think it's the path problem.  I've had very similar problems in the past.
    LVL 84

    Expert Comment

    You probably meant either
    system("/path/to/rsh -l user 'ls -l' > test.txt");
    `/path/to/rsh -l user 'ls -l' > test.txt`;
    you probably didn't mean to do a system call with the output of the command
    does the http user have permission to run as user on
    If the @server array is not defined,
    `/path/to/rcp file.localcopy`
    will interpolate to
    `/path/to/rcp file.localcopy`
    LVL 6

    Expert Comment

    I just copied what was posted and added my $.02.  Ozo, you are correct.  It would be better to use double quotes in the system call rather than the back ticks or just use the back ticks sans system call.

    Good catch.
    LVL 48

    Expert Comment

    You should *always* check the status of a system call to see if it has failed, eg:

    system("rcp file.localcopy") and die "rcp failed $!\n";

    Assuming your webserver is Apache, have you setup ssh keys on the remote host for the 'apache', 'httpd' or 'nobody' user?
    LVL 48

    Expert Comment

    I certainly hope you added error checking.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now