我寫了一個bash腳本來使用telnet發送一封電子郵件。我正在安裝在運行busybox的TS-7260上(它有一個灰殼)。管道到Ash Shell中的命令
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: [email protected]"
sleep 5
echo "rcpt to: [email protected]"
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,順便說一句。
在此先感謝!
注 - 我簡化了腳本只是:
echo "quit" | telnet blah.com port
它正是你在bash期待,但我看到的灰沒有發生。 用「睡眠10」代替echo會顯示睡眠作爲進程運行,但不是telnet。
我假設任何shell都支持set -vx調試跟蹤。試着把它打開,在一個窗口下運行,在另一個窗口運行。看哪裏有差異?灰支持$(... cmd替代)嗎?我想我已經讀過它沒有。使用back-tics(yik)代替?祝你好運! – shellter
什麼,確切地說,不起作用?不同的輸出,顯式錯誤退出,別的? – chepner
它確實看起來像管道以某種方式工作不同 - 「set -vx」顯示正在執行的命令,但是查看系統上運行的進程,telnet永遠不會運行(或運行的時間太短我抓到)。在bash上,它確實存在,而且你看到迴應的迴應。據我所知,$()可以在灰燼上正常工作。 – Narrat1ve