This is NOT the best way :
exec('cd /patto/scripts; ./script.sh');
Passing this to the exec function will always execute ./scripts.sh, which could lead to the script not being executed with the right working directory if the cd
command fails.
Do this instead :
exec('cd /patto/scripts && ./script.sh');
&&
is the AND logical operator. With this operator the script will only be executed if the cd
command is successful.
This is a trick that uses the way shells optimize expression evaluation : since this is an AND operation, if the left part does not evaluate to TRUE then there is not way the whole expression can evaluate to TRUE, so the shells won't event process the right part of the expression.