Page 1 of 1

having troubles with shell_exec()

Posted: Thu Jul 03, 2008 2:21 am
by s.dot
I can execute commands using shell_exec().

Code: Select all

$output = shell_exec('ls -al');
echo '<pre>';
print_r($output);
echo '</pre>';
The above snippet works fine.

However I'm writing a backup script, and I can't get it to tar from php. I'm using the following..

Code: Select all

$output = shell_exec('tar -cvf backup.tar /var/www/vhosts/mysite/httpdocs/');
That isn't working, but when I do it via SSH it works fine.

When I use system($cmd, $retval) ... $retval comes out as 2 which.. i don't know what that means.

I'm thinking the only difference between the non-working command and the working command is that tar is a program execution call whereas ls is a system call?

I'm the only user on a dedicated box so I should be able to get this working.

Re: having troubles with shell_exec()

Posted: Thu Jul 03, 2008 6:49 pm
by s.dot
Well my theory is wrong :P I am able to execute the mysqldump program through shell_exec(). It just doesn't like my tar command for some reason. Again, I can run the command from SSH.

Any thoughts?