Showing posts with label Shell Script To Send an Email. Show all posts
Showing posts with label Shell Script To Send an Email. Show all posts

Tuesday, August 7, 2012

Shell Script To Send an Email

#####################################################################
# Purpose: Design to Email the Log and Out file of given Request ID
# Name   :  Kasinadh Songa
# Version: 1.0
###################################################
# History  -- Intial Version.
###################################################
# -----------------------------------------------------------------+
#  Printing the parameters                                                            +
# -----------------------------------------------------------------+

request_id=$5
email_address=$6
conc_name=$7

echo "*********************************"
echo "Parameters: "
echo "*********************************"
echo " "
echo "Request ID               : " $request_id
echo "Email Address            : " $email_address
echo "concurrent program name  : " $conc_name
echo "*********************************"

log_file=l$request_id.req

out_file_name=o$request_id.out

echo "*********************************"
echo "Log and Out file Names         : "
echo "*********************************"
echo "request id          : " $request_id
echo "log_file            : " $log_file
echo "out_file_name       : " $out_file_name

cd $APPLCSF/$APPLLOG

     if [ ! -f $log_file ]
     then
        echo "Log file does not exist."
        echo "Exiting .."
        exit 1
     else
         echo "Log File exists"
         cp $log_file $HFT_TOP/bin
        echo "Log File copied to : " $HFT_TOP/bin
     fi

cd $APPLCSF/$APPLOUT

     if [ ! -f $out_file_name ]
     then
        echo "Output file  does not exist."
        echo "Exiting .."
      #  exit 1
     else
         echo "Output File exists"
         cp $out_file_name $HFT_TOP/bin
        echo "Out File copied to : " $HFT_TOP/bin
     fi

        echo "log_file_name  : " $log_file
        echo "out_file_name  : " $out_file_name


#### Custom Top
cd $HFT_TOP/bin          
  pwd
  echo "log_file_name in tmp : " $log_file
  echo "out_file_name in tmp : " $out_file_name
  v_file_name=$request_id

  v_file_name_out=o$v_file_name.txt
  v_file_name_log=l$v_file_name.txt

echo v_file_name_log
echo v_file_name_out

# Email the file to the email Address given

export MAILTO=$6

echo " "
(echo "Hi, \n   Find attached the out and log files. \n   Concurrent Program :"$conc_name ; uuencode $log_file $v_file_name_log; uuencode $out_file_name $v_file_name_out;)| mailx -s "Log File and Output file for the request $request_id in $TWO_TASK instance -> $v_file_name" -r "no-reply@harborfreight.com" $MAILTO

#-----------------------------------------
#  Remove Log Files from XXHFT_TOP/sri_edi/tmp
#-----------------------------------------


#### Custom Top
cd $HFT_TOP/bin
rm $log_file
rm $out_file_name

echo "New Out file name     : " $v_file_name
echo " "
echo "********************************"
echo "Program Completed Successfully."
echo "********************************"