2

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

3
  • Run it as a command where? On your server? Commented Jun 26, 2022 at 12:41
  • You might run into troubles when you'd need root permissions because it's not recommended to run Node under root user. Commented Jun 26, 2022 at 12:42
  • run in terminal, and this command doesn't require root Commented Jun 26, 2022 at 12:44

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.