我想使用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这是可能还是不可能?谢谢!
发布于 2012-12-20 02:22:39
这不会起作用,因为echo将输出到tty的stdout,而不是telnet进程的stdin。
我建议为这个任务编写一个expect脚本。也许你可以采用像this这样的东西。
发布于 2013-01-16 04:18:09
这个问题同时在至少四个不同的论坛上被提出。我不知道这种创业会获得什么样的分数,但这里有答案的链接:
https://stackoverflow.com/questions/13958466
复制相似问题