PHP使用ssh2_exec来执行带有查询参数的脚本

时间:2017-09-16 00:18:00

标签: php ssh2-exec

我正在尝试从服务器执行脚本,从MySQL查询中检索参数并存储到structure(list(Datum = structure(c(505L, 504L, 503L, 502L, 501L, 500L), .Label = c("2016-03-03", "2016-03-04", "2016-03-05", "2016-03-06", "2016-03-07", "2016-03-08", "2016-03-09", "2016-03-10", "2016-03-11", "2016-03-12", "2016-03-13", "2016-03-14", "2016-03-15", "2016-03-16", "2016-03-17", "2016-03-18", "2016-03-19", "2016-03-20", ... "2017-07-17", "2017-07-18", "2017-07-19", "2017-07-20", "2017-07-21", "2017-07-22", "2017-07-23"), class = "factor"), Amount = c(1700500L, 2286600L, 3018700L, 2012100L, 2357600L, 1983500L), DM50 = c(230L, 294L, 454L, 267L, 316L, 270L), DM10 = c(226L, 399L, 364L, 330L, 371L, 298L), DM5 = c(516L, 699L, 636L, 573L, 676L, 549L), DM1 = c(665L, 681L, 667L, 606L, 686L, 610L)), .Names = c("Datum", Amount", "X50", "X10", "X5", "X1"), row.names = c(NA, 6L), class = "data.frame") 有没有办法将其用作我脚本的参数?我有一个脚本存储在参数$test

$script

所以我要找的是这样的:<?php include("db.php"); $user = 'user'; $password = 'pwd'; $script = '/my/path/to/script/script.sh'; ... $testResult = mysqli_query($dbConnection, $queryNextTest); $test = $testResult->fetch_object()->test_script; //this is my parameter obtained from query $stream = ssh2_exec($connection, $script); //how can I use test as my paramter to execute the ?> 但是$stream = ssh2_exec($connection, '/my/path/to/script/script.sh $test');不能在引号内。

1 个答案:

答案 0 :(得分:2)

您应该将引号更改为double并使用大括号来表达您的变量,如下所示:

$stream = ssh2_exec($connection, "{$script} {$test}");

甚至没有像这样的花括号:

$stream = ssh2_exec($connection, "$script $test");