通过php exec执行脚本,在服务器上创建一个文件

I have a php script which calls a shell script as below -

#!/bin/bash
timestamp=$(date +"%d-%m-%Y  %H:%M:%S")
echo $timestamp >> results

The php script -

<?php

$mycmd = exec('/bin/bash exectest.sh',$op,$er);
var_dump($mycmd);
var_dump($op);
echo $er."
";

?>

The php script returns error code 1 for $er but when i tried to modify the shell script to just print instead of writing to a file. the Php script then returns 0 and succeeds.

Any ideas of where I need to fix this? I have tried giving the full path for the script and also this is the same case when i tried using a python script in place of a shell script.

Your observation indicates that this is most likely a permission problem, e.g. the user running PHP does not have write permission to either the results file in its current working directory or the directory itself (if the file does not exist yet).

It happened to be running on an AFS machine hence required afs priviledges for httpd.

fs sa . http write

sorted the issue.