Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

switch question for sendmail!

Status
Not open for further replies.

Jimbo2112

IS-IT--Management
Mar 18, 2002
109
GB
Hi All,

I have written a script that sends an automated email from the Unix LAN to my mail address on my pc. The only thing I want it to do that I can't find is put information in the subject header. I am using sendmail. I tried using mailx but that did not work. mailx has the switch -s for subject, but sendmail does not. Am I right in thinking that you should only send preformatted mails with sendmail or is there a switch that I am missing?

Here is the script to understand things a little better

#!/bin/csh

#set echo

if (! -e /dmps/state ) then
touch /dmps/state
else
rm /dmps/state
touch /dmps/state
endif


df -tk /dmps > /dmps/state
set size = `cat /dmps/state | grep "[0-9]%"`
set size = `echo $size | cut -f5 -d' '`
set size = `echo $size | cut -f1 -d'%'`
if ( $size >= 70 ) then

echo "/DMPS IS AT "$size"% PLEASE ATTEND TO THIS IMMEDIATELY " > /dmps/state
echo "Date: "date >> /dmps/state

######## NEED SUBJECT SWITCH FOR BELOW! ############
/usr/lib/sendmail -f administrator -v mjames@bmjgroup.com < /dmps/state
###########################################

else
echo &quot;No worries, /dmps is at &quot;$size&quot;% &quot; > /dmps/state | date >> /dmps/state
endif





Cheers!

Jimbo
 
Hello,
Try this...

#!/bin/csh

#set echo

if (! -e /dmps/state ) then
touch /dmps/state
else
rm /dmps/state
touch /dmps/state
endif


df -tk /dmps > /dmps/state
set size = `cat /dmps/state | grep &quot;[0-9]%&quot;`
set size = `echo $size | cut -f5 -d' '`
set size = `echo $size | cut -f1 -d'%'`
if ( $size >= 70 ) then

echo &quot;/DMPS IS AT &quot;$size&quot;% PLEASE ATTEND TO THIS IMMEDIATELY &quot; > /dmps/state
echo &quot;Date: &quot;date >> /dmps/state

######## NEED SUBJECT SWITCH FOR BELOW! ############
(
echo Subject: Some Subject
echo &quot;&quot;
cat /dmps/state /usr/lib/sendmail -f administrator -v mjames@bmjgroup.com
###########################################

else
echo &quot;No worries, /dmps is at &quot;$size&quot;% &quot; > /dmps/state | date >> /dmps/state
endif
 
Oops, a bit too fast, this should work...



#!/bin/csh

#set echo

if (! -e /dmps/state ) then
touch /dmps/state
else
rm /dmps/state
touch /dmps/state
endif


df -tk /dmps > /dmps/state
set size = `cat /dmps/state | grep &quot;[0-9]%&quot;`
set size = `echo $size | cut -f5 -d' '`
set size = `echo $size | cut -f1 -d'%'`
if ( $size >= 70 ) then

echo &quot;/DMPS IS AT &quot;$size&quot;% PLEASE ATTEND TO THIS IMMEDIATELY &quot; > /dmps/state
echo &quot;Date: &quot;date >> /dmps/state

######## NEED SUBJECT SWITCH FOR BELOW! ############
(
echo Subject: Some Subject
echo &quot;&quot;
cat /dmps/state
) | /usr/lib/sendmail -f administrator -v mjames@bmjgroup.com
###########################################

else
echo &quot;No worries, /dmps is at &quot;$size&quot;% &quot; > /dmps/state | date >> /dmps/state
endif
 
not sure why but I am getting the reply of
&quot;to many ('s&quot;

Any ideas why this is? It looks well grouped to me!

Jimbo
 
Not really...
You do have spaces between the brackets and the | symbol?

Otherwise I can't see it....
 
Thanks all for the help, I evetually got things running properly with the subject being inserted with this solution:


#!/bin/csh

#set echo

if (! -e /dmps/state ) then
touch /dmps/state
else
rm /dmps/state
touch /dmps/state
endif


df -tk /dmps > /dmps/state
set size = `cat /dmps/state | grep &quot;[0-9]%&quot;`
set size = `echo $size | cut -f5 -d' '`
set size = `echo $size | cut -f1 -d'%'`
if ( $size >= 90 ) then

echo Subject: DMPS PARTITION ALERT > /dmps/state
echo &quot;/DMPS IS AT &quot;$size&quot;% PLEASE ATTEND TO THIS IMMEDIATELY &quot; >> /dmps/state

/usr/lib/sendmail -f administrator -v gssempebwa@bmjgroup.com < /dmps/state
/usr/lib/sendmail -f administrator -v vosei@bmjgroup.com < /dmps/state
/usr/lib/sendmail -f administrator -v awaters@bmjgroup.com < /dmps/state
/usr/lib/sendmail -f administrator -v cdavis@bmjgroup.com < /dmps/state
/usr/lib/sendmail -f administrator -v mjames@bmjgroup.com < /dmps/state
else
echo &quot;No worries, /dmps is at &quot;$size&quot;% &quot; > /dmps/state
endif




I think this makes a good `bare bones` email notification model. Hopefully someone else will be able to emply it themselves.

Cheers!

Jimbo
 
I copied this script from aixmurderer.
Works fine on HPUX.

#!/usr/bin/sh
#
# sendattch.sh : Encapsulate standard input as a MIME attachment
# and mail it to the correct destination.
#
# ARGS: 1: File to send as attachment
# 2: Subject
# 3: Delivery Addresses
#

PATH=$PATH:/usr/sbin/
FILE=$1
SUBJECT=$2
INTCHG=`basename $FILE .txt`

USAGE=&quot;sendattch.sh attachment Subject Delivery.addresses&quot;

TEMP=/tmp/$INTCHG.att

# Tidy-up Function

function doExit {
rm -f $TEMP
exit $1
}

# Validate arguments

if [ $# -le 1 ] ;then
echo &quot;Invalid number of arguments: $#\n$USAGE&quot; >&2
doExit -1
fi

shift
shift
TO=$*
# Construct the message

{
echo &quot;To: $TO&quot;
echo &quot;Subject: $SUBJECT&quot;
echo &quot;X-Priority: 3&quot;
echo &quot;MIME-Version: 1.0&quot;
echo &quot;Content-Type: application/msword;&quot;
echo &quot; name=\&quot;$INTCHG\&quot;&quot;
echo &quot;Content-Disposition: attachment;&quot;
echo &quot; filename=\&quot;$INTCHG.txt\&quot;&quot;
echo &quot;Content-Description: $INTCHG&quot;
echo &quot;&quot;
cat $FILE
} > $TEMP

# Send the constructed message

for tt in $TO
do
sendmail $tt < $TEMP
done
doExit $?


Regards Gregor. Gregor.Weertman@mailcity.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top