1

我一直在使用以下 PHP 脚本在服务器上触发 bash 脚本:

<?php
$output = shell_exec('cat update.sh | ssh -l some_user -i key foo.bar.com');
echo "<pre>$output</pre>";
?>

由于我无法控制的问题,我们更改了服务器,我无法运行 PHP(不要问)。我可以在这里使用另一种语言来完成这项任务吗?显然,我可以使用 HTTP POST 来定位。谢谢。

4

3 回答 3

2

您可以使用老式的 cgi-bin 并直接运行 bash 脚本:

#!/bin/bash
x=`cat update.sh | ssh -l some_user -i key foo.bar.com`
echo <<EOL
Content-type: text/html

<pre>$x</pre>
EOL
于 2012-04-30T22:09:22.450 回答
1

您可以直接使用 cgi 运行 bash 脚本。

#!/bin/bash

OUTPUT=`cat update.sh | ssh -l some_user -i key foo.bar.com`

# You must add following two lines before
# outputting data to the web browser from shell
# script
echo "Content-type: text/html"
echo ""

echo "<html><head><title>Demo</title></head><body>"
echo "$OUTPUT <br>"
echo "</body></html>"

来自这里的一些代码

于 2012-04-30T22:07:48.693 回答
0

这取决于服务器配置。任务非常简单,因此您可以在您的提供商提供的每种(我猜)技术中完成它;)

如果您可以访问 perl:

#!/usr/bin/env perl

++$|;
print '<pre>';
system ('your command 2>&1');
print '</pre>';

Python 和许多其他的类似。

于 2012-04-30T22:08:36.493 回答