having troubles with shell_exec()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

having troubles with shell_exec()

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: having troubles with shell_exec()

Post 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?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply