Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
How to execute a linux bash command when clicked on button? The command content is based on user input

HTML: Here I have two inputs


           
           <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: Here I get the result of the inputs and write it as html the result ; inplace of writing it as an result I want to execute it in 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 ;
  
}

I want that that the result of execute function to be run as a linux command

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You will need to use AJAX to send information to the server. The server can possibly then run the bash command.

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();
}

Example for a PHP server

sendCommand.php

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

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

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda