簡體   English   中英

如何在Shell腳本中的變量中捕獲te.net命令的output

[英]How to capture the output of telnet command in a variable in Shell script

我需要使用 shell 腳本在遠程服務器上運行 te.net 命令,並且必須捕獲 output。當我執行以下命令時,它沒有完成,而是掛起。 有人可以建議如何在執行后使用 shell 腳本終止或超時 te.net 命令。

telnet_output=`telnet $server $port`
echo "Output is $telnet_output"

我也嘗試將其寫入文件。 但這在遠程服務器上執行時也會掛起。

opfile="telop.log"
telnet_output=`telnet $server $port | tee $opfile`
op=`cat $opfile`
echo "$op"

試試這個:

telnet_output="$({ sleep 1; echo $'\e'; } | telnet $server $port 2>&1)"
printf "Output is\n%s\n" "$telnet_output"

echo $'\e'te.net發送轉義字符以終止它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM