The Perl script runs fine without any error from command line. The script executes an external command and prints the output on a web page. But somehow when I call it from URL it does not work. Any help will be appreciated. Here is the script:
--test.pl
#!/usr/bin/perl
#
use warnings;
use strict;
use Socket;
I bet your server's running under a different user, most likely www-data. So in that case your server would be trying to log in as user www-data @ test.com.
sudo su www-data
sshpass -p test ssh test.com /usr/contrib/bin/serverinfor -b
That is true , since httpd is ruuning as apache user and that is why we are using sshpass with the another user-id and password......I have tried giving a wrong password and the error log says invalid password. Hence the different user-id is not the issue.
Continuing from ikon... is it executable for 'others' (the third set of owner/group/others)? Especially if you are running this from the web - assume that to fall into the 'others'.
By not work, does it start-up?
If so, then I might be thinking of file locations/directories and their related settings.
No nothing is written into the error log and that is why am so confused. Here is the output of the access log:
10.10.10.10 - - [11/Dec/2008:19:26:37 +0000] "GET /icons/page-background.png HTTP/1.1" 304 - "http://10.10..10.1/cgi-bin/test2.pl" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)"
You have not provided the correct log line. This line is for the image 'page-background.png' indicates the URL is being redirected (to the script??). The redirection is either not completing (and thus no long line is generated) or the log line appears later.
Try simply including an "exit(0);" after your initial "print Content-type" line. You should then see a line in the logs with status 200. Keep moving the "exit()" line and doing a refresh until the log line is no longer 200 (or does not appear).
I tried different perl package to just open a ssh shell to one of the server and executed it via the url and any ideas how to fix this issue? Since if this works, then I can replace my above script with this approach:
#!/usr/bin/perl -w
use warnings;
use strict;
use Socket; #use Net::SSH::Perl;
use Net::OpenSSH;
my $ssh = Net::OpenSSH->new('root:root@10.10.10.1');
$ssh->error and die "Can't ssh : " . $ssh->error;
my $output = $ssh->capture( "ls -la");
$ssh->error and
warn "operation didn't complete successfully: ". $ssh->error;
print $output;
The Error when executed from URL is:
[Fri Dec 12 20:26:52 2008] [error] [client 10.10.10.10] Can't ssh : unable to stablish master ssh connection: the authenticity of the target host can't be established, try loging manually first at /var/www/cgi-bin/test2.pl line 20.
[Fri Dec 12 20:26:52 2008] [error] [client 10.10.10.10] Premature end of script headers: test2.pl
NOTE: The command works fine when executed from command line.......