#!/bin/sh # mailfile a script to send a file and with an email attachment text # # # This section checks the numbers of arguments and rejects if # desired based on the number of argments being incorrect. numarg=$# if [ $numarg -le 5 ] then echo "Usage: mailfile to-email from-email short-filename attachefile full-path subject" echo "Arguments ${numarg}" exit 1 else echo "utility is running...." fi toemail=$1 fremail=$2 flename=$3 attfile=$4 loop=$numarg+1 # subject="${5} ${6} ${5} ${5} ${5} ${5} ${5} ${5}" control=5 while (( control != $loop )) do subject="${subject} ${5}" # echo "${subject}" (( control = control + 1 )) shift done export toemail fremail subject flename attfile # # This section gets a random number, based on process id which can # be used for building unique file names and such. # procnum=$$ echo "Process number : $procnum" # # This section checks the user name and allows rejection on this basis # # if [ "$LOGNAME" = "root" ] then oktorun="Y" echo "User root detected" fi if [ "$LOGNAME" = "sag" ] then oktorun="Y" echo "User sag detected" fi if [ "$LOGNAME" = "coperato" ] then oktorun="Y" echo "User coperato detected" fi if [ "$oktorun" = "Y" ] then echo "user is authorized...$LOGNAME" else echo "user must be sag or oraoper: $LOGNAME" exit 1 fi fbody="/tmp/tempbody$$.dat" fmesg="/tmp/tempmesg$$.dat" ftext="/tmp/temptext$$.dat" export fbody fmesg ftext echo "DMS report attached" > $fbody export EMAIL_TO=$toemail export EMAIL_FROM=$fremail export EMAIL_SUBJECT=$subject export EMAIL_BODY=$fbody export FILE_NAME=$flename export ATTACHED_FILE=$attfile echo "To: $EMAIL_TO" > $fmesg echo "From: $EMAIL_FROM" >> $fmesg # echo "Cc: stevenprotter@juf.org" >> $fmesg echo "Subject: $EMAIL_SUBJECT" >> $fmesg # echo "MIME-Version: 1.0" >> $fmesg # echo 'Content-type: multipart/mixed; boundary="xxxxyyyzzqzzyyyxxxx"' # echo '--xxxxyyyzzqzzyyyxxxx' echo "" >> $fmesg echo "Message file attached" >> $fmesg echo "" >> $fmesg uuencode $attfile $flename >> $fmesg cat $fmesg | /usr/sbin/sendmail -t if [ -f $fbody ] then rm $fbody fi if [ -f $fmesg ] then rm $fmesg fi if [ -f $ftext ] then rm $ftext fi