我写了一个bash脚本,用telnet发送电子邮件。我在运行busyBox的TS-7260上安装它(它有一个灰壳)。
Bash和Ash之间有些不同,我不知道为什么下面的内容不能工作。一定是和我把回声传送到电信网络的方式有关。下面是剧本:
#!/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我也试过在管道之前使用普通括号。我读了艾什的手册,现在还在做些蠢事。我怀疑这是某种儿童程序的事情在进行。
这从巴什很好,顺便说一句。
提前感谢!
注--我将脚本简化为:
echo "quit" | telnet blah.com port它完全符合你的预期,但我看到灰烬中什么也没有发生。用“睡眠10”替换回显显示睡眠作为一个进程运行,而不是telnet。
发布于 2013-07-10 22:40:37
经过更多的实验后,问题不在于shell,而在于在Busybox上实现Telnet。在我的BusyBox (1.00rc2)版本中,任何连接到Telnet的管道都不起作用。
echo blah | telnet -yrDumb至少应该让telnet抱怨一下使用情况。没有。我抓取了最新版本的inetutils (1.9.1),并为TS-7260编写了它的telnet。它现在工作起来就像一个梦(读:它起作用了),并且与我在普通linux上看到的使用telnet和bash的行为是一致的。
谢谢你的帮助!
https://stackoverflow.com/questions/17560555
复制相似问题