Hi Tapani Tarvainen, I tried the script. Good work. But, one problem though. If the mail server is firewalled (Netfilter) and if its blocking the client (one where bash script is run - 192.168.0.10), then `telnet 192.168.0.20 25` will not give any reply but just tries to connect indefinitely. At that moment the script will not give the error message. Can we do anything about it?
Regards, Kurian Thayil. On Wed, 2009-04-15 at 21:48 +0300, Tapani Tarvainen wrote: > On Wed, Apr 15, 2009 at 11:47:43PM +0530, Kurian Thayil > (kurianmtha...@gmail.com) wrote: > > > > [...] I need to execute a script > > only after making sure that I am able to send mail using the relay > > server 192.168.0.20 (Postfix enabled). Is it possible for me to write a > > bash script which check this? > > Doing it in a general, reliable way with bash alone would be very > difficult, but if it's a local server that always responds fast or not > at all, you could try something like this: > > #! /bin/bash > case "$( (sleep 5; echo quit) | telnet 192.168.0.20 25 2>&- )" in > *' > 220 '*) echo Success ;; > *) echo Failed ;; > esac > > -- > Tapani Tarvainen > > -- Kurian Mathew Thayil. (GPG KeyID: E232394F)
signature.asc
Description: This is a digitally signed message part