我有以下功能:
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)) }
sshcommand 函数如下所示:
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); }
我的问题是第一个更新功能等到/var/script/config.sh完成。
但在我的某些情况下,这需要很长时间,所以我只想发送命令并让它在后台运行。
我试图将其更改为/var/script/config.sh | at now + 1 minute但结果相同..
有任何想法吗?