I have a bash script that creates a file and I would like to send an email at the end via telnet. However sometimes it will execute and sometimes it won't.
The command at the end is
cat tempfile | telnet mail.domain.com 25
At the receiving server I see in mail.log the following error when it fails:
improper command pipelining after EHLO from domain.com ....etc
The same script works perfectly if instead of mail.domain.com I start the telnet session in localhost so I'm pretty sure the file format is OK and the rest of the bash script is working too.
I've also tried using standard redirection instead of a pipe
telnet mail.domain.com 25 < tempfile
But again the result sometimes is okay sometimes is not. I think there needs to be a small delay between the redirection and the telnet session command so that the input will be given after the telnet session has been established and a response has been given but I don't know how to do that. I've tried using sleep command in between pipes and redirection and it won't work probably because then the input is redirected to the sleep command.
e.g. cat tempfile | telnet mail.domain.com 25 & sleep 1
The restriction is that I have to do it in a bash script. Is it possible? Also I don't know if it's of any importance but the script used to work between servers in debian squeeze with postfix/courier setup and now the receiving end is set up with debian wheezy and postfix/dovecot.
Thanks in advance for the help
You can implement this by overwriting a line. Use \r to go back to the beginning of the line without writing \n to the terminal. Write \n when you're done to advance the line.
bash is a sh-compatible command language interpreter that executes commands read from the standard input or from a file. bash also incorporates useful features from the Korn and C shells (ksh and csh).
Some versions of Unix and Linux contain Bash system startup scripts, generally under the /etc directories. Bash calls these as part of its standard initialization, but other startup files can read them in a different order than the documented Bash startup sequence.
Click Start, All Apps, under the letter B click Bash on Ubuntu for Windows. Press Windows key + X then click Command prompt, at the command prompt, type: bash then hit Enter. If you want to be able to access the local file system, press Windows key + X, Command Prompt (Admin) then type bash at the prompt.
You could try something like:
(echo -n; sleep 5; cat tempfile) | mail.domain.com 25
to open the connection and write nothing, wait for 5 seconds and write the rest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With