0

I have created shell script:

#!/bin/bash
file="/home/upload/ftp/$1.ifc"
if [ -f "$file" ]
then
    echo "Found."
else
    echo "Not found."
fi
IfcConvert --use-element-guids /home/upload/ftp/${1}.ifc /home/upload/ftp/${1}.dae

When I go to linux terminal and execute it from there with

./script.sh drevodomek

everything works fine.. I got "Found." message and also converter executes

But when I created helper.php

<?php
if (file_exists("/home/upload/ftp/drevodomek.ifc"))  
{ 
    echo "The file exists"; 
} 
else 
{ 
    echo "The file does not exists"; 
}

$cmd = "./script.sh drevodomek";
$results = shell_exec($cmd);
echo $results
?>

I get answers:

"The file exists." from PHP,

"Found." from script.sh

IfcConvert: input file "/home/upload/ftp/drevodomek.ifc" doesn't exists. from script.sh

I am new to linux, has anyone any idea what is the difference running script from terminal and with shell_exec()? Thanks!

  • 1
    Try to use the absolute path to the script rather than assuming the current directory of the PHP instance is the one the script resides in (it likely doesn't). – sticky bit Mar 17 '20 at 12:33

1 Answers1

0

The problem was with the rights, seems like terminal was run as root, but php exetuted script as normal user. Always check your 777!