I can kill a detached screen session with this command:
sudo kill $(screen -ls | awk '/ScreenName/ { print $1 }' | cut -f 1 -d '.')
I am trying to implement this to a simple PHP page:
<?php
if ($_GET['run']) {
$cmd =shell_exec("screen -ls | awk '/ScreenName/ { print $1 }' | cut -f 1 -d '.'");
system('sudo kill $cmd');
?>
<a href="?run=true">Kill The Screen</a>
However, PHP doesn't work. I think it happens because I can't implement $cmd right.Because, when I try to assign the command to $cmd in terminal and execute it, It doesn't work. In short this happens:
~$ cmd="screen -ls | awk '/ScreenName/ { print $1 }' | cut -f 1 -d '.'"
~$ echo $cmd
screen -ls | awk '/ScreenName/ { print $1}' | cut -f 1 -d '.'
~$ $cmd
No Sockets found in /run/screen/S-ubuntu
~$ screen -ls | awk '/ScreenName/ { print $1}' | cut -f 1 -d '.'
28578
Is it the \
escape character? What could be the problem? Is it the apache user running the screen?