Satish
Satish

Reputation: 17467

shell_exec sed -i write file

I have a very simple script run.php

<?php
shell_exec('/var/www/html/insert.sh');
?>

insert.sh

#!/bin/bash
sed -i '/blah/ r file1.txt' config.xml

I am getting following error on apache logs:

sed: couldn't open temporary file ./sedV5qH6N: Permission denied
sed: couldn't open temporary file ./sedBS3zO6: Permission denied
sed: couldn't open temporary file ./sedR4Nw3O: Permission denied

Even i gave it full permission with apache owner. How can I correct the error?

Upvotes: 2

Views: 1504

Answers (1)

Remi Gacogne
Remi Gacogne

Reputation: 4853

In order to be able to edit afile in place, sed needs the right to create a temporary file in the same directory as the file. Clearly, your script does not have the right to write in the given directory.

Upvotes: 2

Related Questions