{"id":49008,"date":"2020-05-15T03:01:13","date_gmt":"2020-05-14T17:01:13","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=49008"},"modified":"2020-05-14T20:14:09","modified_gmt":"2020-05-14T10:14:09","slug":"linux-sendmail-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-sendmail-primer-tutorial\/","title":{"rendered":"Linux sendmail Primer Tutorial"},"content":{"rendered":"<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","protected":false},"excerpt":{"rendered":"<p>The Linux mailx Primer Tutorial outlined some very useful Linux (and Unix and perhaps macOS (or Mac OS X)) command line tools to email useful information to emailees. Today, we want to outline a sendmail alternative approach for reporting purposes, &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-sendmail-primer-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,37],"tags":[234,3299,380,1996,677,707,997,3300,1118,1319,1339],"class_list":["post-49008","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-command-line","tag-echo","tag-email","tag-header","tag-korn-shell","tag-linux","tag-programming","tag-ps","tag-sendmail","tag-tutorial","tag-unix"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/49008"}],"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=49008"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/49008\/revisions"}],"predecessor-version":[{"id":49013,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/49008\/revisions\/49013"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=49008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=49008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=49008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}