【发布时间】:2012-12-07 03:56:24
【问题描述】:
我想使用 telnet 连接到远程主机 没有用户名/密码验证 只是
telnet remotehost
那我需要输入一些初始化命令
然后我需要重复以下命令:
cmd argument
参数是从本地文件中读取的,在这个文件中有很多行,每一行都是一个参数 运行一个“cmd参数”后,远程主机会输出一些结果 它可能会输出带有字符串“OK”的行 或输出多行,其中一行带有字符串“ERROR” 我需要根据结果做一些事情。
基本上,脚本是这样的:
initialization_cmd #some initial comands
while read line
do
cmd $line
#here the remote host will output results, how can I put the results into a variable?
# here I want to judge the results, like
if $results contain "OK";then
echo $line >>good_result_log
else
echo $line >> bad_result_log
fi
done < local_file
the good_result_log and bad_result_log are local files
有没有可能?谢谢!
【问题讨论】:
-
我建议您为
bash或ksh添加标签,以提高您问题的读者群。请注意,telnet标签只有 19 个关注者。除非 bash4 中有支持更好的命名管道式通信的新功能,正如@cmh 建议的那样,expect是解决此类问题的最佳选择。祝你好运。