How to run a shell script from an HTML page?

2019-03-06 14:09发布

I want to make a single button and an input box on an html page input.html, which when clicked should execute a shell script test.sh. The shell script should take that input box string as parameter. The shell script creates an html file out.html (I have created the shell script, which when takes an input string, produces an html file), which then I want to show on original html page input.html.

How can I do this ? Assume everything is running locally i.e. no server thing here.

2条回答
聊天终结者
2楼-- · 2019-03-06 14:14

Browsers won't allow that, that would break the Internet and make hackers very happy if it was possible, yet this can be done with Firefox/Chrome addons or IE activeX controls.

Normally, websites sites that want you to run a script on your terminal will give you a command like this one that you would copy and paste to your terminal:

curl -sS https://example.com/script.sh | sh

Examples:

# meteor.js
curl https://install.meteor.com/ | sudo sh

# node.js
curl -sL https://deb.nodesource.com/setup | bash -

# Composer
curl -sS https://getcomposer.org/installer | php
查看更多
SAY GOODBYE
3楼-- · 2019-03-06 14:19

You might want to try loading that from server side language (like PHP)

<?php
if ($_GET['run']) {
  # This code will run if ?run=true is set.
  exec("/path/to/name.sh");
}
?>

<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
<a href="?run=true">Click Me!</a>
查看更多
登录 后发表回答