[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 926
  • Last Modified:

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.

#!/usr/bin/perl

use warnings;
use CGI;

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

system(`rsh server.domain.com -l user 'ls -l' > test.txt`);
system(`rcp user@server.domain.com:/path/to/file/file.name 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.

 
0
Troyh
Asked:
Troyh
  • 2
  • 2
1 Solution
 
GnarOlakCommented:
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 server.domain.com -l user 'ls -l' > test.txt`);
system(`/path/to/rcp user@server.domain.com:/path/to/file/file.name 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.
0
 
ozoCommented:
You probably meant either
system("/path/to/rsh server.domain.com -l user 'ls -l' > test.txt");
or
`/path/to/rsh server.domain.com -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 server.domain.com?
If the @server array is not defined,
`/path/to/rcp user@server.domain.com:/path/to/file/file.name file.localcopy`
will interpolate to
`/path/to/rcp user.domain.com:/path/to/file/file.name file.localcopy`
0
 
GnarOlakCommented:
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.
0
 
TintinCommented:
You should *always* check the status of a system call to see if it has failed, eg:

system("rcp user@server.domain.com:/path/to/file/file.name 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?
0
 
TintinCommented:
I certainly hope you added error checking.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now