<?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: rsync script to send email after completion or failure in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/rsync-script-to-send-email-after-completion-or-failure/m-p/6809899#M54812</link>
    <description>&lt;P&gt;&amp;gt; [...] but I am not able to get any email. [...]&lt;BR /&gt;&lt;BR /&gt;&amp;gt; sendmail -v "rsync backup completed successfully" salam@xxx.com&lt;BR /&gt;&amp;gt; rsync backup completed successfully @ $(date) for $(hostname)&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; I know nothing, but I don't see how that could work.&amp;nbsp; Have you&lt;BR /&gt;written _any_ script which _can_ send an e-mail message?&amp;nbsp; I'd start with&lt;BR /&gt;that, and _then_ try to add e-mail to your rsync script.&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; A Forum search for keywords like, say:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e-mail script&lt;BR /&gt;should find many examples.&amp;nbsp; Many of them use mailx rather than sendmail.&lt;BR /&gt;In any case, I'd expect most programs of that sort to take their message&lt;BR /&gt;input from stdin, and simply putting a line of text onto your script is&lt;BR /&gt;not a valid way to make that happen.&amp;nbsp; You could use a here-document, or&lt;BR /&gt;a pipeline construct like, say:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo "Your message here." | mailx [...]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt; if [ $? -ne 1 ]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; And if the program can return more values than 0 or 1?&amp;nbsp; A better test&lt;BR /&gt;might be something more like, say:&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if [ $? -eq 0 ]&lt;/P&gt;</description>
    <pubDate>Mon, 09 Nov 2015 19:00:24 GMT</pubDate>
    <dc:creator>Steven Schweda</dc:creator>
    <dc:date>2015-11-09T19:00:24Z</dc:date>
    <item>
      <title>rsync script to send email after completion or failure</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rsync-script-to-send-email-after-completion-or-failure/m-p/6809767#M54810</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written a script for rsync from my production RHEL server to DR RHEL server.&lt;/P&gt;&lt;P&gt;my rsync works fine and has been scheduled in crontab. Now I want to add email notification for each success and failed rsync but I am not able to get any email. email works fine from the server.&lt;/P&gt;&lt;P&gt;can anyone please check &amp;amp; let me know where I am doing mistake in my script:&lt;/P&gt;&lt;P&gt;#!/bin/sh&lt;BR /&gt;#&lt;BR /&gt;# This script calls rsync to copy respective directories&lt;BR /&gt;#&lt;BR /&gt;#&lt;BR /&gt;#!/bin/bash&lt;/P&gt;&lt;P&gt;/usr/bin/rsync -azrv --delete -e "ssh -i /root/rsync/servername-rsync-key" /directory/ root@xx.xx.xxx.xx:/copy-locations &amp;amp;&lt;/P&gt;&lt;P&gt;# send an email if backup failed&lt;/P&gt;&lt;P&gt;if [ $? -ne 1 ]&lt;/P&gt;&lt;P&gt;then&lt;/P&gt;&lt;P&gt;sendmail -v "rsync backup completed successfully" salam@xxx.com&lt;/P&gt;&lt;P&gt;rsync backup completed successfully @ $(date) for $(hostname)&lt;/P&gt;&lt;P&gt;else&lt;BR /&gt;sendmail -v salam@xxxx.xom&lt;/P&gt;&lt;P&gt;"rsync failed" @ $(date) for $(hostname)&lt;/P&gt;&lt;P&gt;fi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help where I am missing in the script. simple rsync sript work fine without any email options.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 11:02:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rsync-script-to-send-email-after-completion-or-failure/m-p/6809767#M54810</guid>
      <dc:creator>Syedfurquan</dc:creator>
      <dc:date>2015-11-09T11:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: rsync script to send email after completion or failure</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rsync-script-to-send-email-after-completion-or-failure/m-p/6809836#M54811</link>
      <description>&lt;P&gt;You're putting your rsync into the background with the '&amp;amp;' at the end of it.&lt;/P&gt;&lt;P&gt;As a result of that you're not getting a true status from the rsync as it hasn't finished yet when you are checking the return code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Remove the '&amp;amp;' from the end of your rsync command and try again.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 15:10:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rsync-script-to-send-email-after-completion-or-failure/m-p/6809836#M54811</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2015-11-09T15:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: rsync script to send email after completion or failure</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rsync-script-to-send-email-after-completion-or-failure/m-p/6809899#M54812</link>
      <description>&lt;P&gt;&amp;gt; [...] but I am not able to get any email. [...]&lt;BR /&gt;&lt;BR /&gt;&amp;gt; sendmail -v "rsync backup completed successfully" salam@xxx.com&lt;BR /&gt;&amp;gt; rsync backup completed successfully @ $(date) for $(hostname)&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; I know nothing, but I don't see how that could work.&amp;nbsp; Have you&lt;BR /&gt;written _any_ script which _can_ send an e-mail message?&amp;nbsp; I'd start with&lt;BR /&gt;that, and _then_ try to add e-mail to your rsync script.&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; A Forum search for keywords like, say:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e-mail script&lt;BR /&gt;should find many examples.&amp;nbsp; Many of them use mailx rather than sendmail.&lt;BR /&gt;In any case, I'd expect most programs of that sort to take their message&lt;BR /&gt;input from stdin, and simply putting a line of text onto your script is&lt;BR /&gt;not a valid way to make that happen.&amp;nbsp; You could use a here-document, or&lt;BR /&gt;a pipeline construct like, say:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo "Your message here." | mailx [...]&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt; if [ $? -ne 1 ]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; And if the program can return more values than 0 or 1?&amp;nbsp; A better test&lt;BR /&gt;might be something more like, say:&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if [ $? -eq 0 ]&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 19:00:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rsync-script-to-send-email-after-completion-or-failure/m-p/6809899#M54812</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2015-11-09T19:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: rsync script to send email after completion or failure</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rsync-script-to-send-email-after-completion-or-failure/m-p/6810328#M54813</link>
      <description>&lt;P&gt;Thank you Patrick &amp;amp; Steven for the help.&lt;/P&gt;&lt;P&gt;Now my scripts working fine and able to get email notification for both success and failed rsync. Now my scripts look like this&lt;/P&gt;&lt;P&gt;#!/bin/bash&lt;BR /&gt;/usr/bin/rsync -azrv --delete -e "ssh -i /root/rsync/xxx-rsync-key" /apps root@xx.xx.xxx.xx:/apps&lt;BR /&gt;&lt;BR /&gt;if [ $? -eq 0 ]&lt;BR /&gt;then&lt;BR /&gt;/usr/lib/sendmail -v "rsync backup completed successfully" salam@xxxx.comt&amp;lt;&amp;lt;EOF&lt;BR /&gt;rsync backup completed successfully @ $(date) for $(hostname)&lt;BR /&gt;EOF&lt;BR /&gt;else&lt;BR /&gt;/usr/lib/sendmail -v salam@xxx.com&amp;lt;&amp;lt;EOF&lt;BR /&gt;"rsync failed" @ $(date) for $(hostname)&lt;BR /&gt;EOF&lt;BR /&gt;fi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2015 07:38:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rsync-script-to-send-email-after-completion-or-failure/m-p/6810328#M54813</guid>
      <dc:creator>Syedfurquan</dc:creator>
      <dc:date>2015-11-11T07:38:25Z</dc:date>
    </item>
  </channel>
</rss>

