• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

172
Views
¿Cómo ejecutar un comando bash de Linux cuando se hace clic en el botón? El contenido del comando se basa en la entrada del usuario

HTML: Aquí tengo dos entradas

 <input id="range3" type="range" min="0" max="255" value="0" /> <input id="num3" min="0" max="255" type="number" value="0" /> <input id="range4" type="range" min="0" max="255" value="0" /> <input id="num4" min="0" max="255" type="number" value="0" />

JS: Aquí obtengo el resultado de las entradas y lo escribo como html el resultado; en lugar de escribirlo como resultado, quiero ejecutarlo en Linux.

 // 30 var range3 = document.getElementById("range3"); var num3 = document.getElementById('num3'); range3.addEventListener('input', function (e) { num3.value = e.target.value; }); num3.addEventListener('input', function (e) { range3.value = e.target.value; }); // 40 var range4 = document.getElementById("range4"); var num4 = document.getElementById('num4'); range4.addEventListener('input', function (e) { num4.value = e.target.value; }); num4.addEventListener('input', function (e) { range4.value = e.target.value; }); function execute(){ document.getElementById("result").innerHTML = "asusctl fan-curve -m " + mode.value + " -D " + "30c:"+ num3.value + ",40C:" + num4.value + " -e true -f "+ unit.value ; }

Quiero que el resultado de la función de ejecución se ejecute como un comando de Linux

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Deberá usar AJAX para enviar información al servidor. El servidor posiblemente pueda entonces ejecutar el comando bash.

 function sendCommand(command) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("myDiv").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", "sendCommand.php?q=" + command, true); xmlhttp.send(); }

Ejemplo para un servidor PHP

enviarComando.php

 <?php $cmd= $_GET['q']; echo shell_exec($cmd);

Cambio: "asusctl fan-curve -m " + mode.value + " -D " + "30c:"+ num3.value + ",40C:" + num4.value + " -e true -f "+ unit.value;

Para: sendCommand("asusctl fan-curve -m " + mode.value + " -D " + "30c:"+ num3.value + ",40C:" + num4.value + " -e true -f "+ unit.value);

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error