我正在嘗試確定端點的IP並將其寫入文件。 當我鍵入:如何僅將命令的結果輸出到文件?
dig +short endpoint.com
在命令提示符下 我得到:
10.50.4.235
然而,當我嘗試在腳本中使用此命令編寫輸出到文件:
dig +short $EndpointName > /home/ec2-user/endpoint-ip.txt
我在文件中得到這個:
endpoint.com
10.50.4.235
它包含變量的值,我寧願只是結果(僅限ip)。非常感謝你的幫助。
嘗試'host endpoint.com'。也許你需要使用'grep'來更好地過濾它。 – Azize
當stdout是終端或文件而不是管道時,某些命令的操作方式會有所不同。試試'dig + short endpoint.com'和'dig + short endpoint.com |貓' –
你需要引用「$ EndpointName」。 – hek2mgl