我希望在一个单行shell中做一些类似于下面的工作。
curl -s icanhazip.com | ssh user@host 'php /path/to/script.php "[PASS_IP_HERE]"'我需要将本地IP传递给远程服务器,最好是一行。
今天我这样做:
curl -s icanhazip.com // manually copy result
ssh user@host 'php /path/to/script.php "[PASTE_RESULT_HERE]"'假设本地IP为1.2.3.4,而远程IP为5.6.7.8,则所需结果更接近于:
> curl -s icanhazip.com
1.2.3.4
> ssh user@5.6.7.8 'php /path/to/script.php "1.2.3.4"'
// How can I pass this dynamically? ---^发布于 2014-11-20 09:00:20
您可以使用命令替换:
ssh -t user@host "php /path/to/script.php $(curl -s icanhazip.com)"发布于 2014-11-20 08:56:51
可能是这样的:
curl -s icanhazip.com | xargs -I{} ssh user@host 'php /path/to/script.php {}'https://stackoverflow.com/questions/27035285
复制相似问题