At the end of my script, I check for specific error codes that are returned from a process I execute within the shell script. Based on the error code, I send an email.
Do I need to turn off exec feature prior to send each email so the piping will work correctly? I would have tested this out before posting but i dont have that ability right now. Thank you all!
Here is my script:
Code:
#!/bin/bash
#:: ------------------------------------------------------------------------
#::-- Script Name: Data_Export.sh
#::
#::-- Description: This script leverages startMaxl.sh to execute
#:: an All Data Essbase export
#::
#::
#::-- Parameters: Call properties file to get environment variables to determine
#:: login info, database, application, etc.
#::
#::-- Author:
#::-- Date:
#:: ------------------------------------------------------------------------
#source /u01/Hyperion_Batch/Scripts/Batch/_env.sh
#::-- Set Script Action --::#
_ACTION=Export
#::-- Set Script Name --::#
#::-- ${_SN%%.sh*} --::
_SN=${0##*/}
#::-- Set Path Variables --::
cd $HOME
_MAINPATH=$(pwd)/Hyperion_Batch/
_LOGPATH=Logs/
_ERRORPATH=Errors/
_SCRIPTPATH=Scripts/
_MAXLPATH=Scripts/MaxL/
_FILEPATH=Files/
_EXPORTPATH=Exports/
#::-- Set Log & Error subdirectories pertaining to the specific process --::#
_PLOGPATH=Data_${_ACTION}_Logs/
_PERRORPATH=Data_${_ACTION}_Errors/
#::-- Set Date and Time Variable --::#
_DAY=$(date +%d)
_MONTH=$(date +%m)
_YEAR=$(date +%Y)
_DATESTAMP=${_YEAR}${_MONTH}${_DAY}
_HOUR=$(date +%H)
_MINUTE=$(date +%M)
_SECOND=$(date +%S)
_TIME=${_HOUR}${_MINUTE}
_DATETIMESTAMP=${_DATESTAMP}_${_TIME}
#::-- Establish STDOUT and STDERROR repositories --::
_ARC_LP=${_MAINPATH}${_LOGPATH}${_PLOGPATH}${_YEAR}_${_MONTH}${_DAY}
_ARC_EP=${_MAINPATH}${_ERRORPATH}${_PERRORPATH}${_YEAR}_${_MONTH}${_DAY}
mkdir -p ${_ARC_LP}
mkdir -p ${_ARC_EP}
#::-- Prepare File Name Format --::#
_HOST=$(hostname -f)
_FN=${_SN%%.sh*}_${_HOST}_${_TIME}
#::-- Establish STDOUT and STDERROR files --::#
_LF=${_ARC_LP}/${_FN}.log
_EF=${_ARC_EP}/${_FN}.err
_MLF=${_ARC_LP}/${_FN}_MAXL.log
#::-- Direct STDOUT and STDERROR to repositories --::#
exec 2>${_EF} > ${_LF}
#::-- If empty, delete YYYY_MMDD error file subdirectory --::
trap "[ -s ${_EF} ] || rm -f ${_EF} && rmdir ${_ARC_EP}" EXIT
#::-- Set MaxL Specific Variables --::#
_ESSB_USER=admin
_ESSB_PSWD=welcome1
_ESSB_SRVR=exalytics-madc-01.zzz.lan
_ESSB_APP=AUTODEMO
_ESSB_DB=FIN_PLAN
_DATA_EXPORTPATH=${_MAINPATH}${_FILEPATH}${_EXPORTPATH}
_EXPORTTYPE=ALL_DATA
_STARTMAXL=/u02/EssbaseServer/essbaseserver1/bin/startMaxl.sh
#::-- Export Script Variables --::#
export _MAINPATH _LOGPATH _ERRORPATH _SCRIPTPATH _MAXLPATH _FILEPATH _EXPORTPATH _PLOGPATH _PERRORPATH
export _DAY _MONTH _YEAR _DATESTAMP _HOUR _MINUTE _SECOND _TIME _DATETIMESTAMP
export _HOST _FN _LF _EF _MLF
export _ESSB_USER _ESSB_PSWD _ESSB_SRVR _ESSB_APP _ESSB_DB _DATA_EXPORTPATH _EXPORTTYPE _STARTMAXL
#:: Begin Script Processing --::#
echo ---------------------------------------------------------
echo ${_SN} beginning processing at ${_TIME}
echo
echo Execute All Data ${_ACTION} against ${_ESSB_APP}
echo ---------------------------------------------------------
. ${_STARTMAXL} ${_MAINPATH}${_MAXLPATH}All_Data_Export.mxl ${_ESSB_USER} ${_ESSB_PSWD} ${_ESSB_SRVR} ${_ESSB_APP} ${_ESSB_DB} ${_DATA_EXPORTPATH} ${_EXPORTTYPE} ${_YEAR}${_MONTH}${_DAY} ${_MLF}
if [ $? -eq 1 ]
then
_TO=
_CC=
_BODY=
_SUBJECT=
_ATTACH=
echo $_BODY|mutt -s "${_SUBJECT}" -a ${_ATTACH} ${_TO} -c ${_CC}
exit 0
elif [ $? -eq 2 ]
then
_TO=
_CC=
_BODY=
_SUBJECT=
_ATTACH=
echo $_BODY|mutt -s "${_SUBJECT}" -a ${_ATTACH} ${_TO} -c ${_CC}
exit 0
elif [ $? -eq 3 ]
then
_TO=
_CC=
_BODY=
_SUBJECT=
_ATTACH=
echo $_BODY|mutt -s "${_SUBJECT}" -a ${_ATTACH} ${_TO} -c ${_CC}
exit 0
else
_TO=
_CC=
_BODY=
_SUBJECT=
_ATTACH=
echo $_BODY|mutt -s "${_SUBJECT}" -a ${_ATTACH} ${_TO} -c ${_CC}
exit 0
fi
I'm not sure why you're asking about exec, but there are definitely other problems in your script.
An exec command will not affect a pipeline whose first process is not reading anything from standard input and whose last process is not writing anything to standard output. If your pipeline writes to standard error, those messages will be written to the file specified by your exec command. If that isn't what you want to happen, you'll need to change something to make it do what you do want; but since you have given us no indication of what you want to happen, there is no way we can guess if your use of exec is right or wrong.
Expanding variables that have been set to empty strings (or to strings containing whitespace characters) without quoting them is a disaster waiting to happen. You have dozens of those.
Every time you execute a command (such as the command [ $? -eq x ] where x is some digit) resets the value of $?. So, only your first test of $? is testing the exit status of your dotting the /u02/EssbaseServer/essbaseserver1/bin/startMaxl.sh command. Presumably, you need something more like:
So you're saying even if the first if conditional isn't met, it still resets '$?' ?
I'm also asking about exec because I have it set above:
Code:
#::-- Direct STDOUT and STDERROR to repositories --::# exec 2>${_EF} > ${_LF}
Then I was wondering for instance if the following line in the first if conditional would just be sent to the error file directory instead of being executed:
Code:
echo $_BODY|mutt -s "${_SUBJECT}" -a ${_ATTACH} ${_TO} -c ${_CC}
As in other scripts, when using exec as I have set up, I need to 'turn it off' in order to use commands such a cat and so on.
Yes. A side effect of executing any pipeline of 1 or more commands is to set the value of the shell special parameter $? to the exit status of that pipeline.
Every command will (re)set the shell's $? parameter, so it can be meaningfully used to evaluate a certain command's success exactly ONCE. To evaluate it several times, assign it to a variable immediately after the command and use that variable hencefoth.
Hi Team,
While sending the email using the mutt command, mail body not appearing properly and attachment it is showing without line breaks and i used the CSS Style (nowrapper )it is working fine.
in this case how to handle the email body, please help me. (1 Reply)
Hi,
I am able to send the mail with attachment through mailx/mutt command.But i am seeing the log file statements all together when i tried to open from my outlook.
log file have the details like below
aaa
bbb
ccc
when i tried to open it from my outlook after receiving the mail attachment... (1 Reply)
Hi Folks -
To make a long story short, this script is loaded into a workbench, executed via workbench user interface, and then I need to display the output on screen. However, I'm using the functions to direct stdout and stderror to their respective directories.
Is there a way to turn that... (5 Replies)
Hello there,
I am using "mutt" command to send e-mails.
mutt -s "Mail subject line" $( printf -- '-a attachment_name') < "mail body file" "e-mail id"
I wish to change the name of the attachment by appending the date to it.
Something like "attachment_name_$DATE.html" in the mutt... (5 Replies)
Hey guys.....
Im new user for linux fedora 20.... i really need help ....... i have no idea why suddently when i turn on my laptop fedora turn to be black screen and ask me loging in , when i loging then nothing happen , it stay at the same screen... then i try to go to "with linux secure...,"... (12 Replies)
Hello All,
I know we can put body inside a mail using -i option for specifying the file which contains body message, is there an option for me to specify body content instead of a file specification only using mutt?
Below is not working and i don't see any options in manual page!
... (4 Replies)
Hi all:
Been racking my brain on this for the last couple of days and what has been most frustrating is that this is the last piece I need to complete a project.
There are numerous posts discussing mutt in this forum and others but I have been unable to find similar issues.
Running with... (1 Reply)
Hi All,
I want to attach the file as well send html content in the mail body using mutt command or any other command.(uuencode is not present). Please help me. Thanks in advance (1 Reply)
Hello,
I am attempting to send emails from AIX 5.2 using either the mailx command or mutt. When I use mutt:
mutt -a jim.txt -s "Test Email" me@mydomain.com
It sends the attachment, but it forces me into the interactive menu.
When I use mailx:
cat data.txt | uuencode... (10 Replies)
hi there,
Would you able to advise that why the syntax or statement below couldn't work as expected ?
/usr/bin/find /backup -name "*tar*" -mtime +2 -exec /bin/rm -f {} \; 1> /dev/null 2>&1
In fact, I was initially located it as in crontab job, but it doesn't work at all. So, I was... (9 Replies)