3
I have a file .sh
and it has variables that I need to receive from PHP, follow an example:
//variavel 1 que preciso receber externamente
NAME=""
//variavel 2 que preciso receber externamente
DIR=""
tar -zcf $HOME.tar.gz $DIR
The file call by PHP serious like this:
shell_exec('sh arquivo.sh');
I just need to know how to send the data of the 2 variables.
Another way would be to send the whole script directly via php shell_exec()
, how would I send a script of that kind?
(That doesn’t work):
shell_exec('VAR=tar -zcf teste.tar.gz teste/testeDir
if [ "$SUCCESS" == "0" ]; then
echo "Sucesso!"
else
echo "Sucesso!"
fi');
I don’t know if it helps, but by PHP itself you can run bash commands by adding variables and picking up the return, in this way it would dispense with the need for this external bash file.
– asfelix
Just one thing: JS is client-side! I don’t understand why JS is involved in this.
– William Aparecido Brandino
I traveled, I thought to do with ajax, but I was going to use php of the same...
– Alan PS
Man this doesn’t work?
echo "{$HOME}";
andecho "{$DIR}";
?– Ivan Ferrer
I don’t understand Ivan, how do I use it ? I read something about sending the variable like this: $page = shell_exec('my_script.sh "{$var1}" "{$var2}"'); but I don’t know if it’s right and I can’t catch it in sh
– Alan PS
kind of:
NAME="$(ls -1)"
.echo "{$NAME}"
– Ivan Ferrer