#!/usr/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 -ne 5 ] then echo "Usage: mailfile to-email from-email subject short-filename attachefile full-path" echo "Arguments ${numarg}" exit 1 else echo "utility is running...." fi toemail=$1 fremail=$2 subject=$3 flename=$4 attfile=$5 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" export fbody 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 echo From: $EMAIL_FROM echo Subject: $EMAIL_SUBJECT echo 'MIME-Version: 1.0' echo 'Content-type: multipart/mixed; boundary="xxxxyyyzzqzzyyyxxxx"' echo '--xxxxyyyzzqzzyyyxxxx' echo '' cat $EMAIL_BODY echo '--xxxxyyyzzqzzyyyxxxx' echo 'Content-Disposition: attachment; filename="'$FILE_NAME'"' echo '' cat $ATTACHED_FILE echo '--xxxxyyyzzqzzyyyxxxx--' } | /usr/sbin/sendmail -v -d8.99 -d38.99 $EMAIL_TO if [ -f $fbody ] then rm $fbody fi