问题
Once in a while, I need to ETRN a couple of backup servers (e.g. after maintenance of my own SMTP server). Normally, I use telnet for that. I go to that server, HELO with my own name and give the ETRN commands. I would like to automate that in a decent way. A simple (but not decent) way would be to start telnet with <<, but the problem is that I do not want to send commands out of order (and the other end may even drop the connection if I do that, haven't tested it yet, but if it works now, it may not work anymore later so I'd like a decent solution and not one that may break later). E.g., I want to wait for the 220 line from the remote SMTP server, then send my HELO, wait for the 250 reply, and only then send the various ETRN commands. How do I do that in bash? Or do I need to use something else, such as python?
来源:https://stackoverflow.com/questions/60352522/how-do-i-create-a-decent-bash-script-to-start-an-etrn-on-a-mail-server