I have following function:
public function update($id){
$data = $this->client_model->get_client_by_id($id);
$sshport = $data['ssh_port'];
$sshcommand = '/var/script/config.sh';
$this->sshcommand($sshport, $sshcommand);
$this->session->set_flashdata('msg', 'Config has been sent');
redirect(base_url('admin/edit/'.$id)) }
The sshcommand function looks like this:
private function sshcommand($port, $command) {
$remotecommand = 'ssh -q root@localhost -o "StrictHostKeyChecking=no" -p'.$port.' "'.$command.'" 2> /dev/null';
$connection = ssh2_connect('controller.server.example.org', 22);
ssh2_auth_pubkey_file($connection, 'root','/root/.ssh/id_rsa.pub','/root/.ssh/id_rsa');
ssh2_exec($connection, $remotecommand); }
My problem is that the first update function wait till /var/script/config.sh
has finished.
But in some of my cases it takes very long, so I just want to sent the command and let it work in the background.
I tried to change it to /var/script/config.sh | at now + 1 minute
but its the same result..
Any Ideas?