How to run . sh file on button

Asked

Viewed 461 times

5

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

in a <a href""></a> also serves.

  • Some of the answers helped solve the problem?

  • Tested and validated, Thank you !

3 answers

4

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

Example:

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

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

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

4

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

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

check if you have the necessary permissions to run this file.

4


Directly by HTML no, with PHP it is possible to do this in some ways, an option is the function shell_exec (not unlike system or exec):

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

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

?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.