텔넷을 사용하여 전자 메일을 보내기위한 bash 스크립트를 작성했습니다. TS-7260에 busyBox (애쉬 셸이 있음)를 설치하고 있습니다.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
나는 파이프보다 너무 낡은 괄호를 사용하려고했습니다. 나는 화산재에 대한 man page를 읽었으며 여전히 바보 같은 짓을하고있다. 나는 그것이 일종의 자식 프로세스 비즈니스 일 것 같습니다.
이것은 bash, btw에서 잘 작동합니다.
미리 감사드립니다. -
주 전 스크립트 단지로 단순화 : 그것은 당신이 bash는 기대 정확히 무엇을
echo "quit" | telnet blah.com port
,하지만 난 아무것도 재에서 일어나지 참조하십시오. echo를 "sleep 10"으로 바꾸면 sleep이 프로세스로 실행되지만 telnet에서는 실행되지 않습니다.
모든 쉘이 set -vx로 디버깅 추적을 지원한다고 가정합니다. 그걸 켜보고, 하나의 창에서 bash로 실행하고 다른 창에서는 재로 실행하십시오. 차이점이있는 곳을 확인하십시오. ash가 $ (... cmd-substitution)을 지원합니까? 내가 읽은 것 같아. 백틱 (yik)을 대신 사용 하시겠습니까? 행운을 빕니다! – shellter
정확히 무엇이 작동하지 않습니까? 다른 출력, 명시 적 오류와 함께 종료, 다른 뭔가? – chepner
파이프가 어떻게 든 다르게 작동하는 것처럼 보입니다. "set -vx"는 시스템에서 실행중인 프로세스를보고 텔넷이 실행되지 않거나 (너무 짧게 실행됩니다. 나는 붙잡는다). bash에서는 응답이 나타나며 응답이 다시 표시됩니다. 그리고 $()는 애쉬에서 잘 작동합니다. 제가 말할 수있는 한. – Narrat1ve