user1471980
user1471980

Reputation: 10636

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

I need to execute commands over ssh in php. Sincere there are multiple of servers, I have to build the $file_name for each server. File name is like this: vmstat_servername. Below is the code.

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

this command is not working because the $file_name inside the single tikcs. Any ideas how I can make this work?

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

Upvotes: 0

Views: 42

Answers (1)

aynber
aynber

Reputation: 23011

Use double quotes, so that the variable will be evaluated:

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

Upvotes: 2

Related Questions