[ad_1]
I have a bash script to auto reconnect broadcast files once every 1 minute with a cronjob. And the bash script is running successfully.
I want every reconnection (every 1 minute) only 1 bash script is running, the previous bash script must be stopped (killed).
How do I kill or ctrl+c using a bash script when a bash script is reconect?
this is my code:
<?php
$address="xxx.xx.2.xx";
$port="xxxx";
// Send Broadcast when HQ sockcet active
if (isset($port) && ($socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP))
&& (socket_connect($socket, $address, $port))) {
$text="Echo Test successful on IP $address, port $port";
//Auto Running Broadcast From HQ when Server Active
$old_path = getcwd();
chdir('/app/Extendedmodule/Socket/cli/');
@$output = shell_exec('./broadcastHq.sh');
chdir($old_path);
echo "<pre>$output</pre>";
socket_close($socket);
}else{
$noConnect="Enable Connect To HQ on IP $address, port $port";
echo "<pre>$noConnect</pre>";
}
?>
MY Bash Script :
#!/bin/sh
nohup /usr/local/zend/bin/php-cli /app/Extendedmodule/Socket/cli/broadcastFrom_Hq.php &
[ad_2]