{"id":3404,"date":"2017-03-22T16:31:26","date_gmt":"2017-03-22T16:31:26","guid":{"rendered":"https:\/\/qbytes.cloud\/?p=3404"},"modified":"2017-03-22T16:31:26","modified_gmt":"2017-03-22T16:31:26","slug":"set-linux-systems-email-updates-available","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2017\/03\/22\/set-linux-systems-email-updates-available\/","title":{"rendered":"Set Linux Systems to email when updates available"},"content":{"rendered":"<p>How to set up Ubuntu and CentOS systems to email notifications when OS updates are available.<\/p>\n<p><!--more--><\/p>\n<h2>Ubuntu:<\/h2>\n<p>You can use tool called apticron to notify you when new updates are available. It sends you e-mail about pending upgrades, also giving you a choice to only send you e-mail about updates not previously notified.<\/p>\n<p>To setup apticron edit \/etc\/apticron\/apticron.conf and change line containing e-mail address:<\/p>\n<p>EMAIL=&#8221;admin@example.com&#8221;<br \/>\nEnter the e-mail address you wish to receive notifications to.<\/p>\n<p>For more information see man apticron.<\/p>\n<h2>CentOS 6 and 7<\/h2>\n<p>Yum-Cron<\/p>\n<p>Yum-cron is a simple way to call yum commands from cron. It provides configuration to keep repository metadata up to date, and to check for, download, and apply updates.<br \/>\nInstall<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">yum install yum-cron\n<\/pre>\n<p>Config Files:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\/etc\/sysconfig\/yum-cron\n\/etc\/yum\/yum-daily.yum\n\/etc\/yum\/yum-weekly.yum\n\n<\/pre>\n<p>Check the files installed:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">rpm -ql yum-cron\n\/etc\/cron.daily\/0yum.cron\n\/etc\/rc.d\/init.d\/yum-cron\n\/etc\/sysconfig\/yum-cron\n\/etc\/yum\/yum-daily.yum\n\/etc\/yum\/yum-weekly.yum\n\/usr\/share\/doc\/yum-cron-3.2.29\n\/usr\/share\/doc\/yum-cron-3.2.29\/COPYING\n\/usr\/share\/man\/man8\/yum-cron.8.gz\n\n<\/pre>\n<p>Configure the service to start a boot:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># chkconfig yum-cron on\n<\/pre>\n<p>Configure the service:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># nano \/etc\/sysconfig\/yum-cron\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># Pass any given paramter to yum, as run in all the scripts invoked\n# by this package.  Be aware that this is global, and yum is invoked in\n# several modes by these scripts for which your own parameter might not\n# be appropriate\nYUM_PARAMETER=\n\n# Don&#039;t install, just check (valid: yes|no)\nCHECK_ONLY=no\n\n# Check to see if you can reach the repos before updating (valid: yes|no)\nCHECK_FIRST=no\n\n# Don&#039;t install, just check and download (valid: yes|no)\n# Implies CHECK_ONLY=yes (gotta check first to see what to download)\nDOWNLOAD_ONLY=no\n\n# Error level, practical range 0-10, 0 means print only critical errors which\n# you must be told, 1 means print all errors, even ones that are not important\n# Level 0 is the default\n# ERROR_LEVEL=0\n\n# Debug level, practical range 0-10, higher number means more output\n# Level 1 is a useful level if you want to see what&#039;s been done and\n# don&#039;t want to read \/var\/log\/yum.log\n# Level 0 is the default\n# DEBUG_LEVEL=1\n\n# randomwait is used by yum to wait random time\n# default is 60 so yum waits random time from 1 to 60 minutes\n# the value must not be zero\nRANDOMWAIT=&quot;60&quot;\n\n# if MAILTO is set and the mail command is available, the mail command\n# is used to deliver yum output\n\n# by default MAILTO is unset, so crond mails the output by itself\n# example:  MAILTO=root\nMAILTO=admin@mydomain.com\n\n# you may set SYSTEMNAME if you want your yum emails tagged differently\n# default is output of hostname command\n# this variable is used only if MAILTO is set too\n#SYSTEMNAME=&quot;&quot;\n\n# you may set DAYS_OF_WEEK to the days of the week you want to run\n# default is every day\n#DAYS_OF_WEEK=&quot;0123456&quot;\n\n# which day should it do cleanup on?  defaults to 0 (Sunday).  If this day isn&#039;t in the\n# DAYS_OF_WEEK above, it&#039;ll never happen\nCLEANDAY=&quot;0&quot;\n\n# set to yes to make the yum-cron service to wait for transactions to complete\nSERVICE_WAITS=yes\n\n# set maximum time period (in seconds) for the yum-cron service to wait for\n# transactions to complete.  The default is 300 seconds (5 minutes)\nSERVICE_WAIT_TIME=300\n\n<\/pre>\n<p>Edit \/etc\/sysconfig\/yum-cron (CentOS 6) to set MAILTO= email address or \/etc\/yum\/yum-cron.conf (CentOS 7) to set email_to= for email notifications. If you use pushover.net for notifications to your mobile or tablet device, you can set<\/p>\n<p>For CentOS 6<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">MAILTO=yourUSERkey+devicename+p1@api.pushover.net\n\n<\/pre>\n<p>For CentOS 7<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">email_to=yourUSERkey+devicename+p1@api.pushover.net\n\n<\/pre>\n<p>For CentOS 7 whether or not if updates are applied are controlled by 3 variables in \/etc\/yum\/yum-cron.conf or \/etc\/yum\/yum-cron-hourly.conf both have the 3 variables disabled = no by default. Need to change them to yes.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># Whether a message should emitted when updates are available.\nupdate_messages = no\n\n# Whether updates should be downloaded when they are available. Note\n# that updates_messages must also be yes for updates to be downloaded.\ndownload_updates = no\n\n# Whether updates should be applied when they are available.  Note\n# that both update_messages and download_updates must also be yes for\n# the update to be applied\napply_updates = no\n\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">Also for CentOS 7, messages either go to stdio or email, default is stdio so for emails set emit_via = email<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># How to send messages.  Valid options are stdio and email.  If\n# emit_via includes stdio, messages will be sent to stdout; this is useful\n# to have cron send the messages.  If emit_via includes email, this\n# program will send email itself according to the configured options.\n# If emit_via is None or left blank, no messages will be sent.\nemit_via = stdio\n\n<\/pre>\n<p>For CentOS 7, using sed replacements to enable yum-cron settings. This sets daily updates for full yum upgrades and hourly to security only updates.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">    EMAIL=your@email.com\n    sed -i &quot;s|^email_to = root|email_to = ${EMAIL}|&quot; \/etc\/yum\/yum-cron.conf\n    sed -i &#039;s|^update_messages = no|update_messages = yes|&#039; \/etc\/yum\/yum-cron.conf\n    sed -i &#039;s|^download_updates = no|download_updates = yes|&#039; \/etc\/yum\/yum-cron.conf\n    sed -i &#039;s|^apply_updates = no|apply_updates = yes|&#039; \/etc\/yum\/yum-cron.conf\n    sed -i &#039;s|^emit_via = stdio|emit_via = email|&#039; \/etc\/yum\/yum-cron.conf\n    sed -i &quot;s|^email_to = root|email_to = ${EMAIL}|&quot; \/etc\/yum\/yum-cron-hourly.conf\n    sed -i &#039;s|^update_cmd = default|update_cmd = security|&#039; \/etc\/yum\/yum-cron-hourly.conf\n    sed -i &#039;s|^update_messages = no|update_messages = yes|&#039; \/etc\/yum\/yum-cron-hourly.conf\n    sed -i &#039;s|^download_updates = no|download_updates = yes|&#039; \/etc\/yum\/yum-cron-hourly.conf\n    sed -i &#039;s|^apply_updates = no|apply_updates = yes|&#039; \/etc\/yum\/yum-cron-hourly.conf\n    sed -i &#039;s|^emit_via = stdio|emit_via = email|&#039; \/etc\/yum\/yum-cron-hourly.conf   \n    egrep &#039;^email_to|^update_messages|^download_updates|^apply_updates|^emit_via&#039; \/etc\/yum\/yum-cron.conf\n    egrep &#039;^email_to|^update_cmd|^update_messages|^download_updates|^apply_updates|^emit_via&#039; \/etc\/yum\/yum-cron-hourly.conf\n\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># service yum-cron restart\n\n<\/pre>\n<p>For CentOS 7 also has an hourly configuration file at \/etc\/yum\/yum-cron-hourly.conf<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># service yum-cron start\n\n<\/pre>\n<p>Cron Job:<\/p>\n<p>You can set up a cron job as well without adding a package.<br \/>\nset up the scrip to run:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># nano \/usr\/local\/bin\/yumcheck\n<\/pre>\n<p>Add the following:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">#! \/bin\/sh\n\nUPDATES=$(yum check-update --quiet | grep -v &quot;^$&quot;)\nUPDATES_COUNT=$(echo $UPDATES | wc -l)\n\nif &#x5B;&#x5B; $UPDATES_COUNT -gt 0 ]]; then\n  echo $UPDATES | mail -s &quot;Updates for $(hostname): ${UPDATES_COUNT}&quot; you@yourdomain.com\nfi\n<\/pre>\n<p>Make executable:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># chmod +x \/usr\/local\/bin\/yumcheck\n<\/pre>\n<p>Set up the cron job:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># nano \/etc\/cron.d\/yumcheck\n<\/pre>\n<p>Add the following to run daily:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># Cronjob to check yum nightly\n30     0      *       *       *       root       \/usr\/local\/bin\/yumcheck\n<\/pre>\n<p>Set up Mail:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># yum -y install mailx\n<\/pre>\n<p>Test:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># echo &quot;Message Body&quot; | mail -s &quot;Email From MAILX&quot; email@yourdomain.com\n<\/pre>\n<p>Other resources:<br \/>\nhttp:\/\/samdoran.com\/automatic-updates-in-rhel-6-and-cent-os-6\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to set up Ubuntu and CentOS systems to email notifications when OS updates are available.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-3404","post","type-post","status-publish","format-standard","hentry","category-administration"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/3404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=3404"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/3404\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=3404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=3404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=3404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}