Click to See Complete Forum and Search --> : PHP and exec()


brockmasterflex
08-20-2004, 01:04 PM
Ok, I have a PHP/HTML form that runs a perl script. The perl script runs fine if I run it, but doesn't seem to work if PHP runs it.

Here is the code:

<html>
<head><title>Torres Email Configuation</title></head>

<?php $fname=$_POST['fname'];
$lname=$_POST['lname'];
$uname=$_POST['uname'];
$passwd=$_POST['passwd'];
$domain="@apolloforest.com";
$cmd="perl sshConnect.pl ".$fname." ".$lname." ".$uname." ".$passwd;
echo "executing command ".$cmd."\n";
exec($cmd);
#echo @output[1];

?>
</html>


and the perl script is....


#!/usr/bin/perl
use Net::SSH::Perl;

$HOSTNAME='torres.maxit.net';
$USERNAME='dan';
$PASSWORD='xxxxxxxxxxx';
$FNAME=$ARGV[0];
$LNAME=$ARGV[1];
$UNAME=$ARGV[2];
$PASSWD=$ARGV[3];

$cmd='sudo /root/scripts/mkuser '.$UNAME.'@apolloforest.com '.$UNAME.' '.$PASSWD.' '.$LNAME.','.$FNAME;
print $cmd."\n";

my $ssh=Net::SSH::Perl->new($HOSTNAME);
$ssh->login($USERNAME, $PASSWORD);

my($stdout, $stderr, $exit)=$ssh->cmd($cmd);
print $stdout;
print $strerr;
print $exit;


I really need to get this script finished today.... any help would be greatly appreciated....

Thanks,
Brock

brockmasterflex
08-20-2004, 02:58 PM
I also tried using passthru(), and popen().... i'm not getting any errors. its strange that the script runs perfectly if I run it.... but asking PHP to run the script does nothing.......

BMF

brockmasterflex
08-20-2004, 05:19 PM
Is it possible to get PHP to switch users? Insted of running the script as apache?

BMF

The Linux Kid
08-20-2004, 06:32 PM
Try chmod 777 on the file.

Failing that chown apache (or whatever your server runs as)

The Linux Kid

brockmasterflex
08-20-2004, 06:50 PM
Thanks for the reply, but I tried that too... and still doesn't work.... apache owns all the scripts and still it won't work.... this is a really weird problem?

The Linux Kid
08-20-2004, 07:57 PM
Have you tried executing the PHP file? ie php <Insert your file name here>

The Linux Kid