python - shell script in PHP/HTML
Get the solution ↓↓↓i have a shell script that will grep a python3 from ps aux
shell script (pythoncheck.sh)
if ps aux | grep -v "grep" | grep "python3" ; then echo "found" ; fi
how do i call this script in html or php, when click a button, if result it 'found' status change to green and if null the status change to red
is this possible with PHP ?
Answer
Solution:
Check out the shell_exec function in PHP.
One way could be to create a PHP file that runs the script and then echos the result, then you can make a network request to this file when the button is clicked and use the response to change your status color.
py-check.php
echo shell_exec('if ps aux | grep -v "grep" | grep "python3" ; then echo "found" ; fi
')
index.html
<button onclick="pyCheck">Check Python Status</button>
<script>
function pyCheck() {
fetch('/py-check.php')
.then(function(response) {
return response.text();
})
.then(function(text) {
if (text === found) {
// Set status green here вњ…
} else {
// Set status red here рџљЁ
}
})
.catch(function(error) {
console.error('Request failed', error)
});
}
</script>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: you must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.