RE: SCP help

From: John Pretti (john_at_web-connected.com)
Date: 05/26/04


To: "'Wiggins d Anconia'" <wiggins@danconia.org>, <beginners@perl.org>
Date: Wed, 26 May 2004 14:31:20 -0500


-----Original Message-----
From: Wiggins d Anconia [mailto:wiggins@danconia.org]
Sent: Wednesday, May 26, 2004 2:09 PM
To: John Pretti; beginners@perl.org
Subject: Re: SCP help

>
> All,
>
> I have developed a CGI that will take information from a CGI based
form and
> SCP a specific file to a remote server. I am having some troubles and I
> think I need to escape something. Anyone have any ideas? Snippet of
code is
> as follows:
>
> # SCP commands
> my $scp_cmd = "/usr/bin/scp";
> my $scp_opts = "-i /root/.ssh/identity ";
>
> # Promote the file to merlin
> system(`$scp_cmd $scp_opts $src_dir/*
> rdwebadmin\@x.x.x.x:/$directories_map{$q->param("promdir")}`);
>
> Error:
> Wed May 26 13:47:47 2004] promote.cgi: Execution of
> /www/web/cgi-sec/merlin/promote.cgi aborted due to compilation errors.
> Warning: Identity file /root/.ssh/identity does not exist.
> Host key verification failed.
> lost connection
> [Wed May 26 13:48:55 2004] [error] [client 199.159.140.172] Premature
end of
> script headers: /www/web/cgi-sec/merlin/promote.cgi
>
> If I do the above command from the command line all works perfectly.
Thanks
> in advance.
>

This appears to be two requests. The first failed because of
compilation, I am assuming it is unrelated, otherwise the script
couldn't work from the command line? The second just indicates that you
are not printing a header (or printing it first).

Additionally you are using backticks within the system as your quotes,
which doesn't make sense and may be the cause of the problem, I am not
sure what Perl will do with that. It will either do the very Perlish
thing of letting most characters act as a quote, or the very Perlish
thing of using the return value from backticks (the output) as arguments
to 'system'. Neither would surprise me.

I am assuming the reason why it fails though is because of the host key
issue and the fact that /root/.ssh/identity wasn't found.

When you run it command line, are you executing it as the user the web
server is running as? Is the script setuid? How is it able to read
root's private key to do authentication, assuming the web server isn't
running as root (yikes)?

Alternatively to shelling out you might consider using the Net::SFTP
module, I have had good luck with it.

http://danconia.org

Thanks for the quick response. I have solved my own problem and realized
that I was running my scp commands from the command line as root, which has
access to that file; however the script runs as apache, which does not have
access to that file. Su to apache and use the correct file and it works.
Sorry to bother you all, but thank you for the quick insight.

Regards,
John



Relevant Pages

  • CGI script: release browser after spawning new process
    ... The purpose of this cgi script is to receive cgi parameters from a user ... filled form and pass them along as command line parameters to another ... perl exec because it spawns this new process and does not return. ...
    (comp.lang.perl.misc)
  • Re: Calling cgi from cgi thru system function. Different behaviour on browser v/s cmd line
    ... The problem is the called CGI program is no longer a "CGI". ... So try to get the param from command line, like regular program in you ... The calling script is a cgi that forks, ...
    (comp.lang.perl)
  • Re: Perl and IIS - script runs but The page cannot be displayed
    ... > one with the variables passed to the script hard coded (although there ... > with absolute paths rather the relative ones the server doesnt mind. ... When executed from a command line, ... CGI programs do not use this function, ...
    (comp.lang.perl.misc)
  • Re: Print recent CGI error
    ... I've sometimes got similar situations in CGI, ... because of a syntax error that kept apache from being able to run the ... What if you just run the script at the command line? ...
    (comp.lang.python)
  • RE: ORA-01017 ... but only when script is run as CGI
    ... Does your CGI have use the same tnsnames.ora file as the ... I'm using current versions of DBI and DBD::Oracle in a CGI script, ... client talking to an Oracle 9 database, ... If I run this script from the command line, ...
    (perl.dbi.users)