Mail Attachment Not Working for Cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mail Attachment Not Working for Cron
# 1  
Old 04-24-2013
Mail Attachment Not Working for Cron

Hi All,

i Have An Script Which is Fetching Data From DB And sending Mail With the Data in Excel Format.

i'm Receiving Mail with Attachment when i Manually Running the script using ksh -x Scriptname or ./ Scriptname.

when i try to run it through cron i'm receiving mail only but Attachment is Not Present in that mail.

Please Suggest ASAP.
# 2  
Old 04-24-2013
Could you please copy / paste the relevant parts of the script, or entire script if not too long, using code tags. Also, using code tags, copy and paste the crontab line. Otherwise, we're just making wild guesses. Smilie
# 3  
Old 04-24-2013
Most likely errors in these type of cases is related to environment.
We can help if you post the script.

Probably, the attachment ( uuencode? ) is not in PATH and you need an absolute path there.
This is just a guess.
# 4  
Old 04-24-2013
hi Hanson,
script is,

Code:
### Local Variables Setup ### 
MAIL_DL="USA.Birlasoft.VCRP.Support@xerox.com,USA.ISP.Critical@xerox.com"
TODAY=`date '+%d-%h-%Y'`
TODAY_TIME=`date '+%d-%h-%Y %H:%M:%S'`
ISP_RESPONSE="${APP_HOME}/tmp/ISP_error_response.log"
ISP_PATH="${APP_HOME}/shell_scripts"
report_sheet="Error_Details.xls"
ERR_CNT=`cat $ISP_RESPONSE|grep 'Total No of -6'|cut -f2 -d:`

### Inbuilt Function Created to send mail to the Distribution List ###
send_email()
{
( cat "$ISP_RESPONSE"; uuencode "$ISP_PATH/$report_sheet" Error_Details.xls; )|mailx -s "-6 Error Status on $TODAY" "$MAIL_DL"
}

### Local Environment Setup ### 
if [ -r $APP_HOME/config/env ];
then
       . $APP_HOME/config/env;
else
          print `date +"%m/%d/%y %H:%M:%S"` " - Environment not available \n" >$ISP_RESPONSE
          cat $ISP_RESPONSE | mailx -s ' Process failed during local environment Setup!!' $MAIL_DL
          exit 1
fi


### Sql Variables Setup ### 
SQL_SETS="
set serveroutput on;
set echo off;
set feedback off;
set heading off;
whenever sqlerror exit 1;
whenever oserror exit 1;"

SQL_SET="
set pages 50000;
set tab on;
#set colsep '   ';
set serveroutput on;
#set trimspool on;
set heading on;
set echo off;
set linesize 220;
set trimout on;
set feedback off;
set space 8;
set lines 32000;"

SQL_CNT_ERR_RECS="SELECT SUM(CNT)
FROM
(
SELECT COUNT(1) CNT FROM VCRADMIN.T523QUERY_RESPONSE_METRICS WHERE TRUNC(REC_TS)=TRUNC(SYSDATE) AND RESULT_CODE='-6'
UNION ALL
SELECT COUNT(1) CNT FROM VCRADMIN.T522REQUEST_RESPONSE_METRICS WHERE TRUNC(REC_TS)=TRUNC(SYSDATE) AND RESULT_CODE='-6'
);"

SQL_CNT_TOTAL_RECS="SELECT COUNT(1) FROM VCRADMIN.T006RAW_RESPONSE_RECORD WHERE TRUNC(REC_TS)=TRUNC(SYSDATE);"

### Connecting to the DataBase ### 
CONN1=`sqlplus -s $DBUSER/$DBPWD@$DBHOST << EOF
$SQL_SETS
$SQL_CNT_ERR_RECS
EOF`

echo "$CONN1" | grep ORA
if [ $? -eq 0 ]
then
      echo "Failure: Issue during counting -6 from the DataBase" > $ISP_RESPONSE
      cat $ISP_RESPONSE | mailx -s ' Process failed during -6 count!!' $MAIL_DL
      exit 0
fi

CONN1=`echo $CONN1|sed -e 's/^ //g'`

### Connecting to the DataBase ### 
CONN2=`sqlplus -s $DBUSER/$DBPWD@$DBHOST << EOF
$SQL_SETS
$SQL_CNT_TOTAL_RECS
EOF`

echo "$CONN2" | grep ORA
if [ $? -eq 0 ]
then
      echo "Failure: Issue during counting of total transaction from the T006 Table" > $ISP_RESPONSE
      cat $ISP_RESPONSE | mailx -s ' Process failed during -6 count!!' $MAIL_DL
      exit 0
fi

CONN2=`echo $CONN2|sed -e 's/^ //g'`

### Connecting to the DataBase ###
CONN3=`sqlplus -s $DBUSER/$DBPWD@$DBHOST << EOF
$SQL_SET
spool $ISP_PATH/report.xls
COLUMN request_number HEADING 'REQUEST_NO'
COLUMN RESULT_CODE HEADING 'CODE'
COLUMN TRANSXTN_ID HEADING 'TRANSXTN_ID'
COLUMN TRANS_TYPE_CD HEADING 'RT'
COLUMN REC_TS HEADING 'DATE WITH TIME'
COLUMN REC_SRC HEADING 'SOURCE'
SELECT request_number,TRANS_TYPE_CD,TRANSXTN_ID,RESULT_CODE,REC_SRC,to_char(REC_TS,'MM/DD/YYYY HH24:MI:SS')REC_TS FROM VCRADMIN.T523QUERY_RESPONSE_METRICS where TRUNC(REC_TS)=To_char(SYSDATE)AND RESULT_CODE='-6'
UNION ALL
SELECT request_number,TRANS_TYPE_CD,TRANSXTN_ID,RESULT_CODE,REC_SRC,to_char(REC_TS,'MM/DD/YYYY HH24:MI:SS')REC_TS FROM VCRADMIN.T522REQUEST_RESPONSE_METRICS where TRUNC(REC_TS)=To_char(SYSDATE) AND RESULT_CODE='-6'
order by REC_TS desc;
spool off

EOF`
echo "$CONN3"> $report_sheet

echo "Total No of -6       : $CONN1 " > $ISP_RESPONSE
echo "Total No of Requests : $CONN2 \n\n" >> $ISP_RESPONSE

echo "Thanks" >> $ISP_RESPONSE
echo "VCRP Support Team \n" >> $ISP_RESPONSE

if [ $CONN1 -gt 0 ]
then
if [ $CONN1 -gt $ERR_CNT ]
then
      send_email
fi
fi

---------- Post updated at 12:36 PM ---------- Previous update was at 12:33 PM ----------

Cron Entry is,

Code:
10 01 * * * ksh 'cd /apps/vcr/appl; . ./config/env;$APP_HOME/shell_scripts/isp_response_status_prod.ksh > /dev/null 2>&1 '


Last edited by Franklin52; 04-24-2013 at 04:12 AM.. Reason: Please use code tags
# 5  
Old 04-24-2013
Could you also use the code tags by highlighting each code block and clicking that little square code button? Thanks.
Code:
Like this
And this
And this

# 6  
Old 04-24-2013
Your script and your crontab entry both depend on $APP_HOME being set, but neither of them do anything to set that variable. The shell's current execution environment will not be available to cron when it runs your script, so you have to explicitly set the environment you need or replace the missing variables with hard-coded values.
# 7  
Old 04-24-2013
Hanson pls look it now..

Code:
ISP_RESPONSE="${APP_HOME}/tmp/ISP_error_response.log"
ISP_PATH="${APP_HOME}/shell_scripts"
report_sheet="Error_Details.xls"

send_email()
{
( cat "$ISP_RESPONSE"; uuencode "$ISP_PATH/$report_sheet" Error_Details.xls; )|mailx -s "-6 Error Status on $TODAY" "$MAIL_DL"
}


SQL_SET="
set pages 50000;
set tab on;
#set colsep ' ';
set serveroutput on;
#set trimspool on;
set heading on;
set echo off;
set linesize 220;
set trimout on;
set feedback off;
set space 8;
set lines 32000;"


CONN3=`sqlplus -s $DBUSER/$DBPWD@$DBHOST << EOF
$SQL_SET
spool $ISP_PATH/report.xls
COLUMN request_number HEADING 'REQUEST_NO'
COLUMN RESULT_CODE HEADING 'CODE'
COLUMN TRANSXTN_ID HEADING 'TRANSXTN_ID'
COLUMN TRANS_TYPE_CD HEADING 'RT'
COLUMN REC_TS HEADING 'DATE WITH TIME'
COLUMN REC_SRC HEADING 'SOURCE'
SELECT request_number,TRANS_TYPE_CD,TRANSXTN_ID,RESULT_CODE,REC_SRC,to_char(REC_TS,'MM/DD/YYYY HH24:MI:SS')REC_TS FROM VCRADMIN.T523QUERY_RESPONSE_METRICS where TRUNC(REC_TS)=To_char(SYSDATE)AND RESULT_CODE='-6'
UNION ALL
SELECT request_number,TRANS_TYPE_CD,TRANSXTN_ID,RESULT_CODE,REC_SRC,to_char(REC_TS,'MM/DD/YYYY HH24:MI:SS')REC_TS FROM VCRADMIN.T522REQUEST_RESPONSE_METRICS where TRUNC(REC_TS)=To_char(SYSDATE) AND RESULT_CODE='-6'
order by REC_TS desc;
spool off

EOF`
echo "$CONN3"> $report_sheet
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

<Mail> attachment param is not working under system function

Hi Guys, I have executed the mail command that has attachment with filename as current date enclosed in system function that is added under awk command. I have used awk command to check if the error code is present in the file then email command sends an email with subject Error Code ,body... (2 Replies)
Discussion started by: reminisce
2 Replies

2. Shell Programming and Scripting

Mail attachment

Hi, I want to send an attachment and content in a single mail using unix command can anyone pls help me? Thanks Naveen A (6 Replies)
Discussion started by: Pranaveen
6 Replies

3. Shell Programming and Scripting

Getting mail with no Attachment

Hi All, my requirement send a mail with attachment a abc.txt file. below is the shell script. #!/usr/bin/ksh set -x #DIR=/appldata/download/mail MAILTO="krupa.behera@kk.com" SUBJECT="Report" BODY="Hi All," ATTACH=/projects/psoft/hrdw/pushreports/crons/temp_out... (5 Replies)
Discussion started by: krupasindhu18
5 Replies

4. Shell Programming and Scripting

how to run a script using cron job and send the output as attachment via e-mail using unix

how to run a script using cron job and send the output as attachment via e-mail using unix. please help me. how my cron job entry should be? As of now my cron job entry is to run the script at specific time, 15 03 * * * /path/sample.sh | mail -s "Logs" email_id In the above entry, what... (8 Replies)
Discussion started by: vidhyaS
8 Replies

5. UNIX for Dummies Questions & Answers

How to send html file in a mail not as an attachment but it should display in the mail in table for

Hi The below script working when we are sending the html as attachment can u please guide how to send thesmae data in table form direct in the mail and not in mail attachment . cat Employee.sql SET VERIFY OFF SET PAGESIZE 200 SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON - HEAD... (0 Replies)
Discussion started by: mani_isha
0 Replies

6. Shell Programming and Scripting

Mail attachment with unix mail

Hi Could someone help me with the details on how to send an attachment through mail in unix. I have an html file in my unix machine and I want this to be send to some mail id, plese help with the steps. Regards Ajay (2 Replies)
Discussion started by: ajaykumarboyana
2 Replies

7. UNIX for Advanced & Expert Users

mailx commannd - Mail and Attachment in same mail

Hi , I am using mailx command for sending the mails. Rightnow I am sending the attachment (by using uuencode $filename) as a seperate mail.I wanna send the attachment also with the same mail. (6 Replies)
Discussion started by: sharif
6 Replies

8. Shell Programming and Scripting

mail with attachment

Hi, I am facing an issue while sending a mail from unix with attachment.the issue is i am able to send a mail with attachment but...after receiving the mail if u see that the text is continous though it was line by line in original.. UUENCODE is the cmd i am using... plz help me in this... (1 Reply)
Discussion started by: param786
1 Replies

9. UNIX for Dummies Questions & Answers

mail attachment

This question has been asked many time before. I did search other questions. But was not able to work out. Really sorry for repeating the same question. I have mail and mailx and sendmail installed. It Tried this uuencode FILENAME.txt FILENAME.txt | mail mymail@yahoo.com the attachment... (3 Replies)
Discussion started by: sushrut
3 Replies
Login or Register to Ask a Question