I want to execute a linux command that returns the currently logged on user in linux.
Using jQuery and ajax, passing this command to the PHP, which will receive and execute this command using exec()
function. The value should be stored and returned.
Upon returning, jquery ajax should return it to a contents of a span tag.
How can this be achieved?
Use .load()
. Something like this:
$('#my-span-id').load('/path/to/page.php');
<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?>
This javascript
sample run a tail
command using node.js
#!/usr/bin/env node
var readline = require('readline');
var cp = require('child_process');
var tail = cp.spawn('tail', ['-500', 'mylogfile.log']);
var lineReader = readline.createInterface(tail.stdout, tail.stdin);
lineReader.on('line', function(line) {
console.log('Line: ' + line);
});
tail.on('close', function(code, signal) {
console.log('ls finished...');
});
Reference Tutorial
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With