How to execute .sh file on button

5

It is possible to execute a file that .sh in a button , example: /bin/importa.sh  

in a <a href""></a> is also good.

    
asked by anonymous 21.10.2016 / 21:02

3 answers

4

Directly from HTML, with PHP it is possible to do this in some ways, one option is shell_exec (not very different from system or exec ):

<form method="post">
  <button type="submit" name="button">Importar</button>
</form>

<?php
if (isset($_POST['button'])) {
    shell_exec("/bin/importa.sh");
}

?>
    
21.10.2016 / 21:49
4

By HTML no, you have to make a call to a PHP page and run the code snippet.

exec("/bin/importa.sh", $output);

Make sure you have the necessary permissions to run this file.

    
21.10.2016 / 21:11
4

If it is freed on your server, use system()

Example:

$comando = "./bin/importa.sh";
$parametros = $_POST['parametros'];
system($comando $parametros,$retorno);

Getting $parametros to pass to the data file for execution, it uses the function to perform bash execution

For more information: View the function page on the PHP website

    
21.10.2016 / 21:09