
Eu tenho um index.html
link que deve remover todos os *.zip do arquivo /mnt/sda1/down
.
Quando clico no link ele começa a baixar e não executa o script sh.
Aqui está o index.html
script e o sh:
#!/bin/sh
cd /mnt/sda1/down
rm *.zip
...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label><a href="delete.sh">DELETE ALL</a> </label>
</form>
</body>
</html>
Responder1
Seu link é um link para um arquivo que seu navegador não reconhece, então ele assume que é um download.
Colocar esse link em <form>
não muda nada. O objetivo do <form>
elemento é reunir parâmetros antes de chamar a URL especificada no atributo “action” (geralmente com um <input type="submit">
elemento no formulário).
Nem está claro se existe um servidor envolvido. Se sim, que tipo é?
Responder2
HTML não tem esse poder. O que você precisa usar é PHP, pois ele pode interagir com seu sistema operacional, já que é uma linguagem de backend.
O que você pode fazer é criar um link para um arquivo php e quando o link for clicado ele irá navegar até o arquivo PHP, executando o script, então você pode dizer a ele para redirecioná-lo de volta para a página inicial ou algo assim:
Índice.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<a href="delete.php">DELETE ALL</a>
</body>
</html>
excluir.php
<?php
echo shell_exec('sh /path/to/delete.sh');
header('Location: /'); #this will take you back to the home page
?>
Postagem original:https://stackoverflow.com/questions/7397672/how-to-run-a-sh-file-from-php