{"id":49023,"date":"2020-05-17T03:01:06","date_gmt":"2020-05-16T17:01:06","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=49023"},"modified":"2020-05-16T18:42:13","modified_gmt":"2020-05-16T08:42:13","slug":"linux-sendmail-mime-type-attachment-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-sendmail-mime-type-attachment-tutorial\/","title":{"rendered":"Linux sendmail Mime Type Attachment Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/sendmail_command_line_mime_type.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux sendmail Mime Type Attachment Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/sendmail_command_line_mime_type.jpg\" title=\"Linux sendmail Mime Type Attachment Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Linux sendmail Mime Type Attachment Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='Linux sendmail Content Type Tutorial' href='#lctt'>Linux sendmail Content Type Tutorial<\/a> had us &#8230;<\/p>\n<ul>\n<li>following up (the Primer tutorial) sending of Content-Type: text\/plain emails via sendmail on Linux &#8230; by &#8230;<\/li>\n<li>allowing for Inline HTML Email (report) sending of Content-Type: text\/html emails via sendmail on Linux  &#8230; but &#8230;<\/li>\n<li>there are more <a target=_blank title='MIME information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/MIME'>Mime Types<\/a> than just these two, but we can make email attachments out of other Mime Type data forms (often regarding &#8220;image&#8221;, &#8220;video&#8221; and &#8220;audio&#8221; media Mime Types)<\/li>\n<\/ul>\n<p> &#8230; and, of course, this opens up this command line Korn Shell scripting to so much more about what the Internet is about &#8220;sharing media files&#8221; (often created on mobile devices by the users themselves).  This ability makes users &#8220;uploaders&#8221; of content, as so many more of us are becoming every day.<\/p>\n<p>We have a favoured approach to interpretive software <font size=1>(though the same approach works well with non-interpretive coding too)<\/font> language (the types that do not need compiling) development where a project &#8230;<\/p>\n<ul>\n<li>starts as a guinea pig exercise to solve a specific set of criteria (remember &#8220;Checking on \/world.php ps -ef Reporting&#8221;?) &#8230; and we &#8230;<\/li>\n<li>genericize by &#8220;parameterizing&#8221; the &#8220;hardcoded words&#8221; in the code &#8230; for example, the color coded &#8220;hardcodings&#8221; of yesterday&#8217;s <a title='Linux sendmail Content Type Tutorial' href='#lctt'>Linux sendmail Content Type Tutorial<\/a> &#8220;First Report&#8221; email creation &#8230;<br \/>\n<code><br \/>\n       echo -e \"<font color=magenta>Content-Type: text\/html\\n<\/font>From: <font color=olive>rmetcalfe@rjmprogramming.com.au<\/font>\\nto:  <font color=green>rmetcalfe15@gmail.com<\/font>\\ncc: <font color=purple>rmetcalfe@rjmprogramming.com.au<\/font>\\nSubject: First <font color=red>Date ps-ef world.php Report<\/font> at `date`\\n<font color=blue>\\n&lt;html&gt;&lt;head&gt;&lt;style&gt; tr:nth-child(even) {background-color: #CCC !important;} tr:nth-child(odd) {background-color: #FFF !important;} &lt;\/style&gt;&lt;\/head&gt;&lt;body&gt;&lt;h1&gt;First Date ps-ef world.php Report at `date`&lt;\/h1&gt;&lt;table style='border:5px dotted olive;width:70%;height:100%;margin: 5 5 5 5;font-family:Courier-New;'&gt;&lt;tr&gt;&lt;th&gt;UID&lt;\/th&gt;&lt;th&gt;PID&lt;\/th&gt;&lt;th&gt;PPID&lt;\/th&gt;&lt;th&gt;C&lt;\/th&gt;&lt;th&gt;STIME&lt;\/th&gt;&lt;th&gt;TTY&lt;\/th&gt;&lt;th&gt;TIME&lt;\/th&gt;&lt;th&gt;CMD&lt;\/th&gt;&lt;\/tr&gt;`cat date_ps_ef_first.txt | sed '\/^\/s\/\/&lt;tr&gt;&lt;td&gt;\/g' | sed 's\/ \\{1,\\}\/&lt;\\\/td&gt;&lt;td&gt;\/g' | awk '{ t=0; while (getline \\$0) { if (t == 0) { print \\\"&lt;tr style=background-color:#e7e7e7 !important;\\\" substr(\\$0,3);  } else { print \\$0; } t=1-t; } }' | sed '\/$\/s\/\/&lt;\\\/td&gt;&lt;\\\/tr&gt;\/g'`&lt;\/table&gt;&lt;\/body&gt;&lt;\/html&gt;<\/font>\" | sendmail -t -f rmetcalfe15@gmail.com<br \/>\n<\/code><br \/>\n &#8230; becomes &#8230;<br \/>\n<code><br \/>\n       echo -e \"<font color=magenta>${mimetype}<\/font>From: <font color=olive>${emailfrom}<\/font>\\nTo:  <font color=green>${emailto}<\/font>\\nCC: <font color=purple>${emailcc}<\/font>\\n${emailbcc}Subject: First <font color=red>${subjmiddle}<\/font> at `date`\\n<font color=blue>${attachrest}<\/font>\" | sendmail -t -f ${emailto}<br \/>\n<\/code><br \/>\n &#8230; via &#8230;\n<\/li>\n<li>command line argument logic (ie. parameterization) helping derive those Korn Shell Script &#8220;$&#8221; variable value determination &#8230;<br \/>\n#!\/bin\/ksh<br \/>\n<code><br \/>\nmimetype=\"Content-Type: text\/html\\\\n\"<br \/>\nemailfrom=\"rmetcalfe@rjmprogramming.com.au\"<br \/>\nemailto=\"rmetcalfe15@gmail.com\"<br \/>\nemailcc=\"rmetcalfe@rjmprogramming.com.au\"<br \/>\nemailbcc=\"\"<br \/>\nsubjmiddle=\"Date ps-ef world.php Report\"<br \/>\nlastcur=\"\"<br \/>\nfilen=\"\"<br \/>\n<br \/>\nattachrest=\"\\\\n&lt;html&gt;&lt;head&gt;&lt;style&gt; tr:nth-child(even) {background-color: #CCC !important;} tr:nth-child(odd) {background-color: #FFF !important;} &lt;\/style&gt;&lt;\/head&gt;&lt;body&gt;&lt;h1&gt;First First ${subjmiddle} at `date`&lt;\/h1&gt;&lt;table style='border:5px dotted olive;width:70%;height:100%;margin: 5 5 5 5;font-family:Courier-New;'&gt;&lt;tr&gt;&lt;th&gt;UID&lt;\/th&gt;&lt;th&gt;PID&lt;\/th&gt;&lt;th&gt;PPID&lt;\/th&gt;&lt;th&gt;C&lt;\/th&gt;&lt;th&gt;STIME&lt;\/th&gt;&lt;th&gt;TTY&lt;\/th&gt;&lt;th&gt;TIME&lt;\/th&gt;&lt;th&gt;CMD&lt;\/th&gt;&lt;\/tr&gt;`cat date_ps_ef_first.txt | sed '\/^\/s\/\/&lt;tr&gt;&lt;td&gt;\/g' | sed 's\/ \\{1,\\}\/&lt;\\\/td&gt;&lt;td&gt;\/g' | awk '{ t=0; while (getline \\$0) { if (t == 0) { print \\\"&lt;tr style=background-color:#e7e7e7 !important;\\\" substr(\\$0,3);  } else { print \\$0; } t=1-t; } }' | sed '\/$\/s\/\/&lt;\\\/td&gt;&lt;\\\/tr&gt;\/g'`&lt;\/table&gt;&lt;\/body&gt;&lt;\/html&gt;\"<br \/>\nif [ ! -z \"$1\" ]; then<br \/>\n while [ ! -z \"$1\" ]; do<br \/>\n  if [ \"`echo \\\"${1}\\\" | tr -d '@'`\" != \"`echo \\\"${1}\\\"\" ]; then<br \/>\n   if [ \"`echo \\\"${emailto}\\\" | tr -d ' '`\" == \"`echo \\\"${emailto}\\\"\" ]; then<br \/>\n     emailto=\"${1} \"<br \/>\n   elif [ \"`echo \\\"${emailcc}\\\" | tr -d ' '`\" == \"`echo \\\"${emailcc}\\\"\" ]; then<br \/>\n     emailcc=\"${1} \"<br \/>\n   else<br \/>\n     emailbcc=\"BCC: ${1}\\\\n\"<br \/>\n   fi<br \/>\n  elif [ -f \"${1}\" ]; then<br \/>\n   if [ ! -z \"${mimetype}\" ]; then<br \/>\n    filen=\"${1}\"<br \/>\n    mimetype=\"\"<br \/>\n    shortf=\"\"<br \/>\n    basechars=\"`base64 ${filen} | tr -d \\\"\\\\n\\\"`\"<br \/>\n    i=0<br \/>\n    flast=\"`echo ${1} | tr '\/' ' ' | sed '\/\\\\\\\\\/s\/\/ \/g'`\"<br \/>\n    for filebits in ${flast}; do<br \/>\n        shortf=$filebits<br \/>\n        ((i=i+1))<br \/>\n    done<br \/>\n    subjmiddle=\"$shortf\"<br \/>\n    attachrest=\"Mime-Version: 1.0\\\\nContent-Type: multipart\/mixed; boundary=\\\"19032019ABCDE\\\"\\\\n\\\\n--19032019ABCDE\\\\nContent-Type: text\/plain; charset=\\\"iso-8859-1\\\"\\\\nContent-Transfer-Encoding: 8bit\\\\n\\\\nFirst ${subjmiddle} at `date`\\\\n\\\\n--19032019ABCDE\\\\nContent-Type: application\/octet-stream; name=\\\"${shortf}\\\";\\\\nContent-Transfer-Encoding: base64\\\\nContent-Disposition: attachment;filename=\\\"${shortf}\\\"\\\\n\\\\n${basechars}\\\\n--19032019ABCDE--\"<br \/>\n   fi<br \/>\n  fi<br \/>\n  shift<br \/>\n done<br \/>\n emailfrom=\"`echo ${emailfrom} | tr -d ' '`\"<br \/>\n emailto=\"`echo ${emailto} | tr -d ' '`\"<br \/>\n emailcc=\"`echo ${emailcc} | tr -d ' '`\"<br \/>\nfi<br \/>\n<\/code><br \/>\n &#8230; thanks to <a target=_blank title='Useful link' href='https:\/\/unix.stackexchange.com\/questions\/223636\/sendmail-attachment\/223650'>this great webpage<\/a> here for great assistance &#8230;the main extra argument can point at a rjmprogramming.com.au domain web server file\n<\/ul>\n<p> &#8230; leaving &#8230;<\/p>\n<p><code><br \/>\nksh date_ps_ef.ksh &gt; \/dev\/null 2&gt; \/dev\/null &amp;<br \/>\n<\/code><\/p>\n<p> &#8230; unchanged as a rjmprogramming.com.au domain &#8220;\/world.php&#8221; ps -ef Report monitor &#8230; and the same code called &#8230;<\/p>\n<p><code><br \/>\nksh date_ps_ef.ksh .\/please_sign.mp4 &gt; \/dev\/null 2&gt; \/dev\/null &amp;<br \/>\n<\/code><\/p>\n<p> &#8230; serving to email a &#8220;First Report&#8221; email attachment that is that &#8220;please_sign.mp4&#8221; video (media) file (playable for the emailee at that email), and if anything changes about that file a &#8220;Changed Report&#8221; email attachment that is that &#8220;please_sign.mp4&#8221; video (media) file (playable for the emailee at that email) will be sent to the same emailee recipients.<\/p>\n<p>And so <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/Mac\/date_ps_ef.ksh---GETME\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/date_ps_ef.ksh---GETME\">date_ps_ef.ksh<\/a> Korn Shell script has a far bigger &#8220;potential footprint&#8221; as of this incarnation.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/linux-sendmail-mime-type-attachment-tutorial\/'>Linux sendmail Mime Type Attachment Tutorial<\/a>.<\/p-->\n<hr>\n<p id='lctt'>Previous relevant <a target=_blank title='Linux sendmail Content Type Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/linux-sendmail-content-type-tutorial\/'>Linux sendmail Content Type Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/sendmail_command_line_content_type.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux sendmail Content Type Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/sendmail_command_line_content_type.jpg\" title=\"Linux sendmail Content Type Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Linux sendmail Content Type Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='Linux sendmail Primer Tutorial' href='#lpt'>Linux sendmail Primer Tutorial<\/a>&#8216;s command line emailing really felt &#8220;command line&#8221;.  We do not consider this an insult per se, and we tend towards &#8220;the badge of honour thinking&#8221; here.  But given reports are more trusted when impactive <font size=1>(we dare to figure)<\/font> &#8230; so &#8230; let&#8217;s add a <i>bit of<\/i> &#8220;spark&#8221; <font size=1>&#8230; luckily the CSS restrictions of HTML Inline Email <a target=_blank title='?' href='https:\/\/www.youtube.com\/watch?v=m7BgOYPNTlA'>&#8220;curbs the enthusiasm&#8221;<\/a> anyway &#8230;<\/font> to the email reporting started yesterday.<\/p>\n<p>The key to what we change is &#8230;<\/p>\n<ul>\n<li>in the <a target=_blank title='Linux sendmail' href='https:\/\/linux.die.net\/man\/8\/sendmail.sendmail'>sendmail<\/a> <a target=_blank title='Linux sendmail headers' href='https:\/\/serverfault.com\/questions\/347602\/sending-e-mail-from-sendmail-with-headers'>headers<\/a> we change <i><a target=_blank title='Content-Type Google search' href='https:\/\/www.google.com\/search?q=content-type+headers&#038;rlz=1C5CHFA_enAU832AU832&#038;oq=content-type+headers&#038;aqs=chrome..69i57j0l7.6429j0j4&#038;sourceid=chrome&#038;ie=UTF-8'>Content-Type<\/a>: text\/plain<\/i> to <i>Content-Type: text\/html<\/i> and that step alone opens the door to <a target_blank title'?' href='https:\/\/www.youtube.com\/watch?v=EK_LN3XEcnw'>&#8220;a little bit of&#8221;<\/a> style in the body section of the email &#8230; but &#8230;<\/li>\n<li>given a lot of CSS3 is not supported in HTML Inline Email styling we had to forgo &#8230;<br \/>\n<code><br \/>\n style=\"background:linear-gradient(top,pink,yellow);\"<br \/>\n<\/code><br \/>\n &#8230; for a linear-gradient background &#8230; and &#8230;<br \/>\n<code><br \/>\n&lt;head&gt;&lt;style&gt; tr:nth-child(even) {background-color: #CCC !important;} tr:nth-child(odd) {background-color: #FFF !important;} &lt;\/style&lt;\/head&gt;<br \/>\n<\/code><br \/>\n &#8230; for alternate table row colouring (as per the heads up at <a target=_blank title='Useful link' href='https:\/\/www.w3.org\/Style\/Examples\/007\/evenodd.en.html'>this link<\/a>, thanks) &#8230; for good &#8216;ol &#8230;<\/p>\n<ol>\n<li><a target=_blank title='Linux sed command information from computerhope' href='http:\/\/www.computerhope.com\/unix\/used.htm'>sed<\/a> (thanks to <a target=_blank title='Useful link, thanks' href='https:\/\/stackoverflow.com\/questions\/23106621\/replace-multiple-consecutive-white-spaces-with-one-comma-in-unix'>this useful link<\/a> for advice)<\/li>\n<li><a target=_blank title='awk' href='https:\/\/www.gnu.org\/software\/gawk\/manual\/gawk.html'>awk<\/a> (and its excellent <a target=_blank title='awk getline' href='https:\/\/www.gnu.org\/software\/gawk\/manual\/html_node\/Getline.html'><i>getline<\/i><\/a> method, and thanks to <a target=_blank title='Useful link' href='https:\/\/docs.freebsd.org\/info\/gawk\/gawk.info.Getline.html'>this useful link<\/a> for advice)<\/li>\n<\/ol>\n<p> &#8230; scripting interventions instead &#8230; so that for that &#8220;First Report&#8221; we output the report (largely) in an HTML table element as per &#8230;<br \/>\n<code><br \/>\n       echo -e \"Content-Type: text\/html\\nFrom: rmetcalfe@rjmprogramming.com.au\\nto:  rmetcalfe15@gmail.com\\ncc: rmetcalfe@rjmprogramming.com.au\\nSubject: First Date ps-ef world.php Report at `date`\\n\\n&lt;html&gt;&lt;head&gt;&lt;style&gt; tr:nth-child(even) {background-color: #CCC !important;} tr:nth-child(odd) {background-color: #FFF !important;} &lt;\/style&gt;&lt;\/head&gt;&lt;body&gt;&lt;h1&gt;First Date ps-ef world.php Report at `date`&lt;\/h1&gt;&lt;table style='border:5px dotted olive;width:70%;height:100%;margin: 5 5 5 5;font-family:Courier-New;'&gt;&lt;tr&gt;&lt;th&gt;UID&lt;\/th&gt;&lt;th&gt;PID&lt;\/th&gt;&lt;th&gt;PPID&lt;\/th&gt;&lt;th&gt;C&lt;\/th&gt;&lt;th&gt;STIME&lt;\/th&gt;&lt;th&gt;TTY&lt;\/th&gt;&lt;th&gt;TIME&lt;\/th&gt;&lt;th&gt;CMD&lt;\/th&gt;&lt;\/tr&gt;`cat date_ps_ef_first.txt | sed '\/^\/s\/\/&lt;tr&gt;&lt;td&gt;\/g' | sed 's\/ \\{1,\\}\/&lt;\\\/td&gt;&lt;td&gt;\/g' | awk '{ t=0; while (getline \\$0) { if (t == 0) { print \\\"&lt;tr style=background-color:#e7e7e7 !important;\\\" substr(\\$0,3);  } else { print \\$0; } t=1-t; } }' | sed '\/$\/s\/\/&lt;\\\/td&gt;&lt;\\\/tr&gt;\/g'`&lt;\/table&gt;&lt;\/body&gt;&lt;\/html&gt;\" | sendmail -t -f rmetcalfe15@gmail.com<br \/>\n<\/code><br \/>\n &#8230; and for the &#8220;Changed Report&#8221; we output the report (largely) in an HTML textarea element as per &#8230;<br \/>\n<code><br \/>\n       echo -e \"Content-Type: text\/html\\nFrom: rmetcalfe@rjmprogramming.com.au\\nto:  rmetcalfe15@gmail.com\\ncc: rmetcalfe@rjmprogramming.com.au\\nSubject: Changed Date ps-ef world.php Report at `date`\\n\\n&lt;html&gt;&lt;body&gt;&lt;h1&gt;Changed Date ps-ef world.php Report at `date`&lt;\/h1&gt;&lt;textarea rows=${cur} style='background-color:#e7e7e7;border:5px dotted olive;width:70%;height:100%;margin: 5 5 5 5;font-family:Courier-New;'&gt;`diff date_ps_ef_first.txt date_ps_ef_next.txt`&lt;\/textarea&gt;&lt;\/body&gt;&lt;\/html&gt;\" | sendmail -t -f rmetcalfe15@gmail.com<br \/>\n<\/code>\n<\/li>\n<\/ul>\n<p>To get to the HTML textarea element stage <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/Mac\/date_ps_ef.ksh-GETME\">we made these changes<\/a>, and then to progress onto a tabular &#8220;First Report&#8221; <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/Mac\/date_ps_ef.ksh--GETME\">we applied these changes<\/a> to the final <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/date_ps_ef.ksh--GETME\">date_ps_ef.ksh<\/a> Korn Shell script that finished up on the rjmprogramming.com.au web server, again, started via &#8230;<\/p>\n<p><code><br \/>\nksh date_ps_ef.ksh &gt; \/dev\/null 2&gt; \/dev\/null &amp;<br \/>\n<\/code><\/p>\n<p> &#8230; to &#8220;do its th<strike>a<\/strike>ing&#8221; in the background, quietly, like.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/linux-sendmail-content-type-tutorial\/'>Linux sendmail Content Type Tutorial<\/a>.<\/p-->\n<hr>\n<p id='lpt'>Previous relevant <a target=_blank title='Linux sendmail Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/linux-sendmail-primer-tutorial\/'>Linux sendmail Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/sendmail_command_line.pdf\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux sendmail Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/sendmail_command_line.jpg\" title=\"Linux sendmail Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Linux sendmail Primer Tutorial<\/p><\/div>\n<p>The <a title='Linux mailx Primer Tutorial' href='#lpt'>Linux mailx Primer Tutorial<\/a> outlined some very useful Linux (and Unix and perhaps macOS (or Mac OS X)) command line tools to email useful information to emailees.<\/p>\n<p>Today, we want to outline a <a target=_blank title='Linux sendmail' href='https:\/\/linux.die.net\/man\/8\/sendmail.sendmail'>sendmail<\/a> alternative approach for reporting purposes, perhaps, again, from the command line, and we&#8217;d like to thank <a target=_blank title='Useful link' href='https:\/\/www.linuxquestions.org\/questions\/linux-newbie-8\/sendmail-subject-and-body-4175623014\/'>this link<\/a> for great advice, here.<\/p>\n<p>Along the way, today, towards the creation of a Korn Shell Script solution to a reporting issue where we wanted to monitor a Linux system&#8217;s &#8220;<a target=_blank title='Linux ps' href='http:\/\/man7.org\/linux\/man-pages\/man1\/ps.1.html'>ps<\/a> -ef&#8221; mentions of &#8220;\/world.php&#8221; (for our rjmprogramming.com.au CentOS Linux web server operating system), and email relevant report information as a result of that monitoring environment changing, we wanted to emphasise &#8230;<\/p>\n<ul>\n<li>usefulness of Linux <a target=_blank title='Linux echo' href='http:\/\/man7.org\/linux\/man-pages\/man1\/echo.1.html'>echo<\/a>&#8216;s -e switch &#8230;<br \/>\n<blockquote cite='http:\/\/man7.org\/linux\/man-pages\/man1\/echo.1.html'><p>\n-e     enable interpretation of backslash escapes\n<\/p><\/blockquote>\n<p> &#8230; to help out the construction of sendmail headers that require line feed characters to work\n<\/li>\n<li>usefulness of <a target=_blank title='Linux backtick' href='https:\/\/unix.stackexchange.com\/questions\/27428\/what-does-backquote-backtick-mean-in-commands'>Linux\/Unix backtick<\/a> to include varieties of data into the <i>subject<\/i> and <i>body<\/i> sections of the email<\/li>\n<li>usefulness of sendmail <a target=_blank title='Linux sendmail headers' href='https:\/\/serverfault.com\/questions\/347602\/sending-e-mail-from-sendmail-with-headers'>headers<\/a> featuring heavily in the Korn Shell Email (from command line) commands <font color=blue>as per<\/font> &#8230;<br \/>\n<code><br \/>\necho -e \"<font color=blue>Content-Type: text\/plain\\nFrom: rmetcalfe@rjmprogramming.com.au\\nto:  rmetcalfe15@gmail.com\\ncc: rmetcalfe@rjmprogramming.com.au\\nSubject: First Date ps-ef world.php Report at `date`\\n\\n`cat date_ps_ef_first.txt`<\/font>\" | sendmail -t -f rmetcalfe15@gmail.com<br \/>\necho -e \"<font color=blue>Content-Type: text\/plain\\nFrom: rmetcalfe@rjmprogramming.com.au\\nto:  rmetcalfe15@gmail.com\\ncc: rmetcalfe@rjmprogramming.com.au\\nSubject: Changed Date ps-ef world.php Report at `date`\\n\\n`diff date_ps_ef_first.txt date_ps_ef_next.txt`<\/font>\" | sendmail -t -f rmetcalfe15@gmail.com<br \/>\n<\/code>\n<\/li>\n<li>usefulness of <a target=_blank title='Linux &#038; background processing' href='https:\/\/www.google.com\/search?q=Linux+%26+background+process&#038;rlz=1C5CHFA_enAU832AU832&#038;oq=Linux+%26+background+process&#038;aqs=chrome..69i57j0l7.8476j0j7&#038;sourceid=chrome&#038;ie=UTF-8'>&#038; background processing<\/a> as per the &#8230;<br \/>\n<code><br \/>\nksh date_ps_ef.ksh &gt; \/dev\/null 2&gt; \/dev\/null &amp;<br \/>\n<\/code><br \/>\n &#8230; we ended up setting off our <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/date_ps_ef.ksh_GETME\">date_ps_ef.ksh<\/a> Korn Shell Script reporter &#8230;<br \/>\n<code><br \/>\n#!\/bin\/ksh<br \/>\n# date_ps_ef.ksh<br \/>\n# Report on world.php<br \/>\nlastcur=\"\"<br \/>\nwhile [ 0 -lt 1 ]; do<br \/>\n   cur=\"`ps -ef | grep '\/world.php' | grep -v 'grep ' | wc -l`\"<br \/>\n   echo \"`date` $cur\"<br \/>\n   if [ \"$lastcur\" != \"$cur\" ]; then<br \/>\n     if [ -z \"$lastcur\" ]; then<br \/>\n       echo \"`ps -ef | grep '\/world.php' | grep -v 'grep '`\" &gt; date_ps_ef_first.txt<br \/>\n       echo -e \"Content-Type: text\/plain\\nFrom: rmetcalfe@rjmprogramming.com.au\\nto:  rmetcalfe15@gmail.com\\ncc: rmetcalfe@rjmprogramming.com.au\\nSubject: First Date ps-ef world.php Report at `date`\\n\\n`cat date_ps_ef_first.txt`\" | sendmail -t -f rmetcalfe15@gmail.com<br \/>\n     else<br \/>\n       echo \"`ps -ef | grep '\/world.php' | grep -v 'grep '`\" &gt; date_ps_ef_next.txt<br \/>\n       echo -e \"Content-Type: text\/plain\\nFrom: rmetcalfe@rjmprogramming.com.au\\nto:  rmetcalfe15@gmail.com\\ncc: rmetcalfe@rjmprogramming.com.au\\nSubject: Changed Date ps-ef world.php Report at `date`\\n\\n`diff date_ps_ef_first.txt date_ps_ef_next.txt`\" | sendmail -t -f rmetcalfe15@gmail.com<br \/>\n       cat date_ps_ef_next.txt &gt; date_ps_ef_first.txt<br \/>\n     fi<br \/>\n     lastcur=\"$cur\"<br \/>\n   fi<br \/>\n   # ps -ef | grep '\/world.php' | grep -v 'grep '<br \/>\n   sleep 30<br \/>\ndone<br \/>\nexit<br \/>\n<\/code>\n<\/li>\n<\/ul>\n<p>Take a look at some of all this in action with today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/sendmail_command_line.pdf\">PDF presentation<\/a>.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/linux-sendmail-primer-tutorial\/'>Linux sendmail Primer Tutorial<\/a>.<\/p-->\n<hr>\n<p id='lpt'>Previous relevant <a target=_blank title='Linux mailx Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/linux-mailx-primer-tutorial\/'>Linux mailx Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/mailx\/Linux_mailx_uuencode.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux mailx Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Linux\/mailx\/Linux_mailx_uuencode.jpg\" title=\"Linux mailx Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Linux mailx Primer Tutorial<\/p><\/div>\n<p>Think Linux and you may not associate it with email, but Linux can be excellent for many email requirements, especially using mailx and uuencode.   The use of uuencode allows you to give your email an attachment, and the mailx -s switch for the subject of the email can be used for both the purpose it was meant for, that is to establish an email subject, and with a stretch of imagination of usage, the body text, because of the quirk whereby anything after the first line of the subject will spill over into the body text of the email.   So, am sure there would be limits to the length of this body text, but you can often be brief when there is a good attachment to provide your email recipient.   Naturally, in the day and age of worry about computer viruses, your attachment will most likely be vetted by the receiving email client software for viability, so be aware of this.   Other than all that, this method of sending emails is potentially very powerful.  Notice that great way Linux and Unix can use `cat body.txt` type of syntax to embed one command within another &#8230; sometimes Linux is so simple, powerful, brilliant!   You may have noticed how short all the commands in Linux and Unix tend to be, and that is because it was intended to be short and powerful, and this is brilliant.<\/p>\n<p><font color=blue>Background reading for tutorial:<\/p>\n<ul>\n<li><a target=_blank title='mailx' href='http:\/\/linux.die.net\/man\/1\/mailx'>mailx<\/a><\/li>\n<li><a target=_blank title='uuencode' href='http:\/\/linux.die.net\/man\/1\/uuencode'>uuencode<\/a><\/li>\n<\/ul>\n<p><\/font>\n<\/p>\n<p>Here is a tutorial that introduces you to some email with attachment, subject and body text from the Linux <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/Linux\/mailx\/Linux_mailx_uuencode.jpg'>command line<\/a>.<\/p>\n<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d4673' onclick='var dv=document.getElementById(\"d4673\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Linux\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d4673' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d49008' onclick='var dv=document.getElementById(\"d49008\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/email\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d49008' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d49016' onclick='var dv=document.getElementById(\"d49016\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/command-line\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d49016' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d49023' onclick='var dv=document.getElementById(\"d49023\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/mimetype\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d49023' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday&#8217;s Linux sendmail Content Type Tutorial had us &#8230; following up (the Primer tutorial) sending of Content-Type: text\/plain emails via sendmail on Linux &#8230; by &#8230; allowing for Inline HTML Email (report) sending of Content-Type: text\/html emails via sendmail on &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-sendmail-mime-type-attachment-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,33,37],"tags":[1885,111,113,122,234,1667,281,3299,380,418,1839,2718,1996,576,590,623,677,707,760,792,1668,2732,1886,3301,997,3300,1115,1118,1319,1339,1369],"class_list":["post-49023","post","type-post","status-publish","format-standard","hentry","category-elearning","category-software","category-tutorials","tag-argument","tag-attachment","tag-audio","tag-awk","tag-command-line","tag-content-type","tag-css","tag-echo","tag-email","tag-file","tag-genericization","tag-genericize","tag-header","tag-html","tag-image","tag-interpretive","tag-korn-shell","tag-linux","tag-media","tag-mime","tag-mime-type","tag-mimetype","tag-parameter","tag-parameterization","tag-programming","tag-ps","tag-sed","tag-sendmail","tag-tutorial","tag-unix","tag-video"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/49023"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=49023"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/49023\/revisions"}],"predecessor-version":[{"id":49028,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/49023\/revisions\/49028"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=49023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=49023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=49023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}