我希望在单行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? ---^
答案 0 :(得分:2)
可能类似于:
curl -s icanhazip.com | xargs -I{} ssh user@host 'php /path/to/script.php {}'
答案 1 :(得分:1)
您可以使用命令替换:
ssh -t user@host "php /path/to/script.php $(curl -s icanhazip.com)"