<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Unable to send email via echo to show SAS session status in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854765#M337830</link>
    <description>&lt;P&gt;Without being able to test anything (no UNIX available):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;remove the semicolon after the if&lt;/LI&gt;
&lt;LI&gt;use double square brackets ( if [[ $rc -gt 1 ]] )&lt;/LI&gt;
&lt;LI&gt;where is your fi to terminate the if?&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Fri, 20 Jan 2023 08:40:10 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-01-20T08:40:10Z</dc:date>
    <item>
      <title>Unable to send email via echo to show SAS session status</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854725#M337816</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using the following code to send an email when an SAS session finishes successfully or fails midway. For some reason, I never receive the emails.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;${sasroot}/sas -autoexec $autoexec -memsize 8G -sortsize 4G -cpucount 4 \
-sysin $sascoderoot/$progname.sas \
-log $projlog/${progname}_${logtimestamp}.log \
-print $projout/${progname}_${logtimestamp}_${sector}.lst \
-noterminal -nodms -errorabend; rc=$?
echo $?

# For SAS: 0=ok, 1=warn, &amp;gt;1=error.
if [ $rc -gt 1 ];
then
subject="$sector $jobdesc process was unsuccessful"
msg="$sascoderoot/$progname.sas sector $sector had errors (SAS rc=$rc). Please Review the log ($projlog/${progname}_${logtimestamp}.log). Please do not reply to sender."
echo -e "$msg" | mail -s "$subject" -r "$sender" "$failemail"
exit $rc
else
subject="$sector $jobdesc process was successful"
msg="$sascoderoot/$progname.sas $sector sector ran successfully. Please do not reply to sender."
echo -e "$msg" | mail -s "$subject" -r "$sender" "$supportemail"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;autoexe, sysin, log and lst are all successfully executed. `$sender`, `$failemail` and `&lt;BR /&gt;$supportemail` are all defined. What could be the possible cause?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 02:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854725#M337816</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2023-01-20T02:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to send email via echo to show SAS session status</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854732#M337817</link>
      <description>&lt;P&gt;Looks like you are running a shell script. Assuming it to be a bash script.&lt;/P&gt;
&lt;P&gt;I suggest the following.&lt;/P&gt;
&lt;PRE&gt;1. Add this to the top of the script and capture the output to another file.
set -x
Thus if your script is send_mail.sh then for debugging run
./send_mail.sh &amp;gt; debug_output.txt
2.Echo all shell variable to see if they are assigned proper values.
Thus you musg echo $msg, $subject $sender etc
3.Unless you are using escaped characters the consider removing -e after echo in
echo - $msg | ...
4.I  prefer enclosing shell variable in curly braces. Thus
${msg} in place of $msg,  ${subject} in place of $subject.
.5.Read the debug_output.txt and you may get an idea of whats going on.



&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Jan 2023 03:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854732#M337817</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2023-01-20T03:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to send email via echo to show SAS session status</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854736#M337820</link>
      <description>Hi, I added the debugging feature and echo shell variables. There were no issues. On debug_output.txt, I can only echo before if [ $rc -gt 1 ]; , if I place it at the end, the echo code will not output. Still no email received.</description>
      <pubDate>Fri, 20 Jan 2023 04:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854736#M337820</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2023-01-20T04:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to send email via echo to show SAS session status</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854765#M337830</link>
      <description>&lt;P&gt;Without being able to test anything (no UNIX available):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;remove the semicolon after the if&lt;/LI&gt;
&lt;LI&gt;use double square brackets ( if [[ $rc -gt 1 ]] )&lt;/LI&gt;
&lt;LI&gt;where is your fi to terminate the if?&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Fri, 20 Jan 2023 08:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854765#M337830</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-20T08:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to send email via echo to show SAS session status</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854846#M337866</link>
      <description>&lt;P&gt;Hello I have modified the operative portion of your email script.&lt;BR /&gt;This works on bash shell on Red Hat / Cent. Adjust to your script.&lt;BR /&gt;Reply if you are having issues&lt;/P&gt;
&lt;PRE&gt;#!/bin/bash
set -x
##Variable definitions
SECTOR=10
JOBDESC=some_job
PROJLOG=projlog
PROGNAME=program
SAS_CODE_ROOT="your_root_path"
LOG_TIME_STAMP=`date +%Y-%m-%d_%H_%M_%S`
SENDER="info@example.com"
SUPPORT_EMAIL="info@example.com"
FAIL_EMAIL="info@example.com"
RETURN_CODE=0;
#### Send emai1####
if [[ ${RETURN CODE} -gt 1 ]];
then
SUBJECT="${SECTOR}+ ${JOBDESC} process was unsuccessful"
MSG= "${SAS_CODE_ROOT}/${PROGNAME}.sas SECTOR ${SECTOR had errors (SAS Return Code is ${RETURN CODE}). Please Review the log (/${PROJLOG}/${PROGNAME}_${LOG_TIME_STAMP}.log).
Please do not reply to SENDER echo ${MSG}"
echo -e "${MSG}" | mailx -s "${SUBJECT}" -r "${SENDER}" "${FAIL_EMAIL}"
exit ${RETURN CODE} 
else

SUBJECT="${SECTOR} ${JOBDESC) process was successful"
MSG="${SAS_CODE_ROOT}/${PROGNAME}.sas ${SECTOR} SECTOR ran successfully. Please do not reply to SENDER"
echo -e "${MSG}" | mailx -s "${SUBJECT}" -r "${SENDER]" "${SUPPORT_EMAIL}" 
fi&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Jan 2023 15:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854846#M337866</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2023-01-20T15:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to send email via echo to show SAS session status</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854866#M337876</link>
      <description>&lt;P&gt;I applied changes suggested by both responses (fi was present in the program, I made a typo when I made this post). There is still no email.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;${sasroot}/sas -autoexec ${autoexec} -memsize 8G -sortsize 4G -cpucount 4 \
-sysin ${sascoderoot}/${progname}.sas \
-log ${projlog}/${progname}_${logtimestamp}.log \
-print ${projout}/${progname}_${logtimestamp}_${sector}.lst \
-noterminal -nodms -errorabend; rc=$?
echo $?

# For SAS: 0=ok, 1=warn, &amp;gt;1=error.
if [[ ${rc} -gt 1 ]]
then
        subject="${sector}+ ${jobdesc} process was unsuccessful"
        msg="${sascoderoot}/${progname}.sas sector ${sector} had errors (SAS rc=${rc}). Please Review the log (/${projlog}/${progname}_${logtimestamp}.log). Please do not reply to sender."
        echo -e "${msg}" | mailx  -s "${subject}" -r "${sender}" "${failemail}"
        exit ${rc}
else
        subject="${sector}+ ${jobdesc} process was successful"
        msg="${sascoderoot}/${progname}.sas ${sector} sector ran successfully. Please do not reply to sender."
        echo -e "${msg}" | mailx  -s "${subject}" -r "${sender}" "${supportemail}"
fi

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Jan 2023 16:31:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854866#M337876</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2023-01-20T16:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to send email via echo to show SAS session status</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854937#M337919</link>
      <description>&lt;P&gt;The script I gave works. My presumption is that you are running Linux .&lt;BR /&gt;Please test to see only the portion of the code I gave on your system. In place of &lt;A href="mailto:info@example.com" target="_blank"&gt;info@example.com&lt;/A&gt; have your email address.&lt;BR /&gt;If that does not work then try this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;echo -e "Hello" | mailx  -s "Test" -r "Your email id" "email id"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that does not work, then what is your OS and what shell you are using. (echo ${SHELL} shold give info about your shell).&lt;BR /&gt;Do approach your OS admin for assistance,&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 22:55:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854937#M337919</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2023-01-20T22:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to send email via echo to show SAS session status</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854942#M337922</link>
      <description>&lt;P&gt;Have you tried the mailx command by typing in the correct details at an OS command line? If it doesn't work from a command line it surely wont work in a script. If that's the case then get help from your IT administrator to get it working.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Jan 2023 00:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/854942#M337922</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-01-21T00:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to send email via echo to show SAS session status</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/855276#M338056</link>
      <description>&lt;P&gt;It's some problem on my server. The code itself should be correct.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 02:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-send-email-via-echo-to-show-SAS-session-status/m-p/855276#M338056</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2023-01-24T02:29:01Z</dc:date>
    </item>
  </channel>
</rss>

