如何执行php中包含变量的ssh命令


how do you execute ssh commands that has variables in them in php

我需要在php中通过ssh执行命令。真诚地说,有多个服务器,我必须为每个服务器构建$file_name。文件名如下:vmstat_servername。下面是代码。

$file_name="/var/vmstat_".$value;

此命令不起作用,因为单个tikc中有$filename。你知道我该怎么做吗?

$line1= $ssh->exec('head -3 $file_name');

使用双引号,以便对变量求值:

$line1= $ssh->exec("head -3 $file_name");