管道到Ash Shell中的命令

时间:2013-07-10 00:32:17

标签: bash pipe telnet busybox ash

我写了一个bash脚本来使用telnet发送电子邮件。我将它安装在运行busyBox(有灰壳)的TS-7260上。

Bash和Ash之间有些不同,我无法弄清楚为什么以下不起作用。它必须是我将回声传递给telnet的方式。这是脚本:

#!/bin/ash

# Snag all the error messages from a given date, open a telnet connection to an outgoing mail server, stick the logs in an email, and send it.
# Tue Jul  2 14:06:12 EDT 2013
# TMB

# Tue Jul  9 17:12:29 EDT 2013
# Grepping the whole error file for WARNING and the piping it to a grep for the date took about four minutes to complete on the gateway.  This will only get longer and the file will only get bigger as time goes by.
# Using tail to get the last 5000 lines, I get about three days of errors (2000 of them are from one day, though)
# Getting 5000 lines, then searching them by WARNING and then DATE took 15 seconds on the gateway.

yesterdayDate=$(./getYesterday)

warningLogs=$(tail -5000 /mnt/sd/blah.txt | grep WARNING | grep "$yesterdayDate")

sleep 30

{
sleep 5
echo "ehlo blah.com"
sleep 5
echo "auth plain blah"
sleep 5
echo "mail from: blah@blah.com"
sleep 5
echo "rcpt to: me@blah.com"
sleep 5
echo "data"
sleep 5

echo "Hi!"
sleep 1
echo "Here are all the warnings and faults from yesterday:"
sleep 1
echo "$yesterdayDate"
sleep 1
echo "NOTE: All times are UTC."
sleep 1
echo ""
sleep 1
echo "$warningLogs"
sleep 10
echo ""
sleep 1
echo "Good luck,"
sleep 1
echo "The Robot"
sleep 5
echo "."
sleep 20
echo "quit"
sleep 5
} | telnet blah.com port

exit

我在管道之前尝试过使用普通括号。我已经阅读了关于灰的手册页,我仍在做一些愚蠢的事情。我怀疑这是一种儿童流程业务。

从bash,btw。

可以正常工作

提前致谢!


注意 - 我将脚本简化为:

echo "quit" | telnet blah.com port

它完全符合你对bash的期望,但我发现灰烬没有发生任何事情。 用“sleep 10”替换echo表示睡眠作为一个进程运行,但不是telnet。

1 个答案:

答案 0 :(得分:1)

经过一些实验,问题不在于shell,而是在Busybox上实现了Telnet。在我的BusyBox版本(1.00rc2)上,将任何内容传送到Telnet都不起作用。

echo blah | telnet -yrDumb

至少应该让telnet抱怨使用情况。它没有。 我抓住了最新版本的inetutils(1.9.1),并为TS-7260编译了telnet。它现在就像一个梦想(阅读:它可以工作),并且与我在普通linux盒子上使用telnet和bash看到的行为一致。

感谢您的帮助!