【发布时间】:2019-02-18 23:15:47
【问题描述】:
我有以下功能:
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,但结果相同..
有什么想法吗?
【问题讨论】:
-
这主要是相关的。这有帮助吗? stackoverflow.com/questions/1019867/…
-
谢谢,但我也尝试重定向标准输出和标准错误,但没有成功。