using the system command with "rcp and rsh"

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.

Who is Participating?
GnarOlakConnect With a Mentor Commented:
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.
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`
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.
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?
I certainly hope you added error checking.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.