shell script not sending mail

Hi,

I have shell script which checks the filesystem check but does not send the mail. I might be missing something very simple.. could you please help?

#!/bin/sh
_servers="machine name"
_out="/tmp/output.$$"
_email="me@there.com"
_sub="Disk Space Report $(date)"

_mail=/usr/bin/mail
>$_out
for s in $_servers
do
     df -h >>$_out
done
$_mail -s "${_sub}" $_email <$_out

Your code cannot work the way it seems you want it work, as posted.
What UNIX and shell are you on? Do you have ssh keys et up on your servers for the user account that is supposed to run the script?

Can you send mail from the command line even?

sendmail -v your.address@your.domain
Subject: This is a test
Text
Text
More text
CNTL-D

This will give verbose output and should be similar to this:-

$ sendmail -v your.address@your.domain
Subject: This is a test
Text
Text
More text
your.address@your.domain... Connecting to mailgateway.your.domain. via relay...
220-SMTP Relay
220 Warning: no name found in DNS for your host address
>>> EHLO localserver.your.domain
250-your.domain
250-SIZE 0
250-ETRN
250-ENHANCEDSTATUSCODES
250-DSN
250-VRFY
250-AUTH 
250 8BITMIME
>>> MAIL From:<userid@localserver.your.domain> SIZE=34
250 2.0.0 userid@localserver.your.domain OK
>>> RCPT To:<your.address@your.domain>
250 2.0.0 your.address@your.domain OK
>>> DATA
354 Ready for data
>>> .
250 2.0.0 Message received OK
your.address@your.domain... Sent (Message received OK)
Closing connection to mailgateway.your.domain.
>>> QUIT
221 2.0.0 uisl.co.uk closing

Getting something failing in this output indicates a number of things, the most common being:-

  • There is not a DS record defined in sendmail.cf (somewhere below /etc depending on you OS) saying where to route remote mail to.
  • There is a firewall or other reason you cannot connect to the mail router specified above. This is SMTP port 25. Try telnet mailgateway.your.domain 25 to test it opens.

I hope that this helps, or at least rules something out.

Robin
Liverpool/Blackburn
UK

@Jim. The machine is a solaris sun sparc. Iam little cautious in setting up the ssh. I though the ssh was required to check for remote servers. I might be wrong here. new to shell scripting. Is there a diff way or coding to acheive this(check file system on a particular unix box?

What version of Solaris?

I don't think that the Solaris mail command has a -s switch . I think that you should be using mailx not mail .

HI Methyl, Thank you for that. it worked.

But the output is not a aligned one.

Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c1t0d0s0      2.9G   2.3G   497M    83%    /
/proc                    0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
fd                       0K     0K     0K     0%    /dev/fd
/dev/dsk/c1t0d0s3      3.8G   2.2G   1.6G    57%    /var
swap                    14G   176K    14G     1%    /var/run
swap                    15G   981M    14G     7%    /tmp
/dev/dsk/c5t600C0FF00000000000441C4672DDFB00d0s0    33G    30G   3.2G    91%    /u05
/dev/dsk/c5t600C0FF00000000000441C167EE03F00d0s1    33G    31G   1.6G    95%    /u04
/dev/dsk/c5t600C0FF00000000000441C167EE03F00d0s0    33G    15G    18G    45%    /u03
/dev/md/dsk/d0          33G    24G   9.5G    72%    /app
/dev/dsk/c5t600C0FF00000000000441C3EB9BADC00d0s1    33G    29G   4.2G    88%    /u02
/dev/dsk/c5t600C0FF00000000000441C3EB9BADC00d0s0    33G    31G   1.6G    96%    /u01
/dev/dsk/c5t600C0FF00000000000441C6101145502d0s0   134G   126G   7.0G    95%    /u08
/dev/dsk/c5t600C0FF00000000000441C6101145500d0s0   134G   122G    12G    92%    /u10
/dev/dsk/c5t600C0FF00000000000441C6101145501d0s0   134G   111G    22G    84%    /u09
/dev/dsk/c5t600C0FF00000000000441C55A9336D01d0s0   134G   130G   2.9G    98%    /u07
/dev/dsk/c5t600C0FF00000000000441C55A9336D00d0s0   134G   123G    10G    93%    /u06

Could you help?

My script:

#!/bin/bash
_servers=xxx
_out="/tmp/output.$$"
_email="am@here.com"
_sub="Disk Space Report $(date)"
##_ssh=/usr/bin/ssh
_mailx=/usr/bin/mail
>$_out
for s in $_servers
do
     df -h >>$_out
done
$_mailx "${_sub}" $_email <$_out