I have a script which runs on multiple servers. Some servers are using sSMTP and some are using postfix.
I want to find which version of sendmail my server is running in runtime, because
sSMTP 2.64 (Not sendmail at all)
VER=$(sendmail -V 2>/dev/null)
if [[ "sSMTP" == $VER* ]]; then
echo $BODY | sendmail $EMAIL #sSMTP
echo $BODY | sendmail -t $EMAIL #postfix
How about this?
type -p sendmail | xargs dpkg -S
Some packages put it in
/usr/lib, others in
/usr/sbin, etc. This obviously requires them to be on your
dpkg -S tells you the name of the package which installed a file, and
type -p is used to find
sendmail on your
PATH so we can pass that to
dpkg -S. This obviously requires a Debian-based distro (Ubuntu, Mint, what have you).
ssmpt system, with
/usr/lib on the
PATH, the output is
On a Postfix system with a slightly different
I don't think I have an Exim or Qmail system where I can try this, but they should be predictably similar.
As an aside, if you want to pass a multi-line string such as an email message to
sendmail by way of a pipe from
echo, you will need to quote the multi-line variable in order for it to work.
echo "$body" | sendmail -t
If you want to use
sendmail -t, the
"$body" should contain the
To: header for
sendmail to parse -- this is what the
-t option does, so I don't think you want a variable with a recipient address in this scenario.
Also, don't use uppercase for your private variable names; uppercase variable names are reserved for system use.
Finally, as already commented elsewhere, I believe both SSMTP and Postfix support
sendmail -t, as does practically every other Sendmail implementation I have seen. So in the end, I don't think you actually need this code to achieve that goal.