<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Modu Michael on Medium]]></title>
        <description><![CDATA[Stories by Modu Michael on Medium]]></description>
        <link>https://medium.com/@cloudboy?source=rss-c37f87192bb8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Q-86-vEXW9g9Yp3r9v3eSA@2x.jpeg</url>
            <title>Stories by Modu Michael on Medium</title>
            <link>https://medium.com/@cloudboy?source=rss-c37f87192bb8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 08:20:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cloudboy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to use cronjobs to automate email alerts and system memory checks.]]></title>
            <link>https://medium.com/@cloudboy/how-to-use-cronjobs-to-automate-email-alerts-and-system-memory-checks-a17c01a7ad0b?source=rss-c37f87192bb8------2</link>
            <guid isPermaLink="false">https://medium.com/p/a17c01a7ad0b</guid>
            <category><![CDATA[email-alert]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[bash-script]]></category>
            <category><![CDATA[cronjob]]></category>
            <dc:creator><![CDATA[Modu Michael]]></dc:creator>
            <pubDate>Wed, 28 Sep 2022 01:26:13 GMT</pubDate>
            <atom:updated>2022-09-28T01:30:13.184Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is a sequel to my previous article on “<strong>How to write a bash script to send email notifications of system memory (RAM) at a specified time</strong>”. if you haven&#39;t read it, here is the <a href="https://medium.com/@cloudboy/how-to-write-a-bash-script-to-send-email-notifications-of-system-memory-ram-at-a-specified-time-c3bb4363f313"><strong>link</strong></a> to it. There are instances where you might want to write different scripts for each task or one for all. This guide uses cronjobs to automate the execution of two bash scripts.</p><p>Pre-requisites:</p><ul><li>A simple mail transfer protocol has already been set up and is working correctly. (It can send test emails to your address)</li><li>Good internet connection.</li></ul><p>Two bash scripts will be created, memory_log.sh and email.sh. The memory_log.sh will handle the creation and logging of the system memory in the log file while email.sh, will send the emails at the specified time. You can run the commands as a root user by running:</p><pre>sudo su</pre><p>Also, make sure your time and timezone are correct by running</p><pre>timedatectl</pre><p>If it is incorrect, run</p><pre>timedatectl set-timezone Africa/Ghana</pre><pre>#thats if you are in ghana</pre><p><strong>To create the scripts run:</strong></p><pre>touch memory_log.sh<br>touch email.sh</pre><p><strong>To edit the scripts:</strong></p><pre>nano memory_log.sh<br>nano email.sh</pre><h4>Below are the contents for memory_log.sh and email.sh respectively:</h4><pre>#!/bin/bash</pre><pre>path=/home/vagrant/memory_logs/log_file.log</pre><pre>touch ${path}</pre><pre>date &gt;&gt; ${path}</pre><pre>free -h &gt;&gt; ${path}</pre><pre>echo &quot;-------&quot; &gt;&gt; ${path}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*TsRT34R7ZCNC6lksTYgMpw.png" /></figure><p>Script to send emails:</p><pre>#!/bin/bash</pre><pre>path=/home/vagrant/memory_logs/log_file.log</pre><pre>email=your_email_address</pre><pre>echo &quot;Here is your system memory report!&quot; | mutt -a ${path} -s &quot;SYSTEM MEMORY REPORT&quot; -- ${email} &amp;&amp; sudo rm -f ${path}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4RI2GN48D7PeTrFvXMw9YA.png" /></figure><p>After the contents have been added make sure to save and exit using ctrl + o, enter key, and ctrl + x.</p><h4>Breakdown:</h4><p>In the memory_log.sh, the path variable specifies the path to the log file to be created and used, the touch command creates the log file at the file path, free -h displays the system memory information in human-readable form i.e MiB, and the echo “ — — “ just separates the different logs.</p><p>in the email.sh, the path is also specified as well as it is where the file to be sent is and it should be deleted after the email is sent.</p><p>Note: Make sure to run</p><pre>chmod u+x memory_log.sh<br>chmod u+x email.sh</pre><h4>Creating the cronjobs to send the log system memory and send email</h4><p>To insert cronjobs, run this command:</p><pre>crontab -e</pre><p>Two cronjobs will be used as shown below:</p><pre>* * * * * bash /home/vagrant/memory_logs/memory_log.sh</pre><pre>0 12 * * * bash /home/vagrant/memory_logs/email.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*gNlo40jBiuuA_sNvdqdpjA.png" /><figcaption>crontab</figcaption></figure><p>The first cronjob runs every minute, logging system memory (memory_log.sh) while the second one executes at 12 noon every day of the month. (email.sh)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*zZ4lExsV0Uj0g2giVkYV6w.png" /></figure><p>This is just a guide to show how cronjobs can be used to schedule and execute tasks. The commands can be altered to suit your needs and make sure the file path corresponds to yours as this is all mine.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a17c01a7ad0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to write a bash script to send email notifications of System Memory (RAM) at a specified time.]]></title>
            <link>https://medium.com/@cloudboy/how-to-write-a-bash-script-to-send-email-notifications-of-system-memory-ram-at-a-specified-time-c3bb4363f313?source=rss-c37f87192bb8------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3bb4363f313</guid>
            <category><![CDATA[bash-script]]></category>
            <category><![CDATA[shell-script]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[cronjob]]></category>
            <category><![CDATA[email]]></category>
            <dc:creator><![CDATA[Modu Michael]]></dc:creator>
            <pubDate>Tue, 20 Sep 2022 03:05:29 GMT</pubDate>
            <atom:updated>2022-10-28T07:57:27.423Z</atom:updated>
            <content:encoded><![CDATA[<p>Bash scripting is a convenient way to automate tasks on any Linux system, and scripting knowledge is essential for a DevOps Engineer. The Bash program reads and executes the bash script line by line.</p><h3><strong>Introduction</strong></h3><p>This tutorial is a guide to putting basic Linux and bash scripting knowledge to use. It assumes that the user is familiar with Linux commands and bash syntax. <strong>The project is to write a bash script to run every hour, saving system memory (RAM) usage to a specified file and at midnight it sends the content of the file to a specified email address, then starts over for the new day.</strong></p><p>This project is in Three parts:</p><ol><li>Email setup using SSMTP, Mailutils, and Mutt.</li></ol><p>You’d have to set up a new email address to receive the email alerts. You can use an existing one but setting up a new one is more secure.</p><p>2. Write a bash script to automate the task.</p><p>3. Scheduling a cronjob for timely execution of the bash script.</p><h3>Email setup using SSMTP.</h3><p>SMTP <strong>(Simple Mail Transfer Protocol) </strong>or<strong> </strong>SMTP<strong> (Secure Simple Mail Transfer Protocol) </strong>is a program used <strong>to deliver emails from a local computer to a configured mailhost (mailhub — Here Gmail will be used.). </strong>It is sometimes paired with other libraries e.g Mailutils, Mutt, etc.</p><h4>Installing Packages.</h4><p>Use the commands below to install SSMTP, Mailutils, and Mutt Respectively!</p><p>Run:</p><pre># timedatectl set-timezone Africa/Lagos</pre><pre># sudo su</pre><pre># apt update</pre><p><strong>For SSMTP:</strong></p><pre><em># apt-get install ssmtp</em></pre><p><strong>For Mailutils:</strong></p><pre><em># apt-get install mailutils</em></pre><p><strong>For Mutt:</strong></p><pre><em># apt-get install mutt</em></pre><p>Confirm that all packages have been correctly installed, Next step is to edit the SSMTP configuration file.</p><pre><em># nano /etc/ssmtp/ssmtp.conf</em></pre><p>Your configuration file will look like this:</p><figure><img alt="Unedited ssmtp configuration file." src="https://cdn-images-1.medium.com/max/746/1*HePvFKts3ZxKFcq1-Q06XQ.png" /></figure><p>Now you edit the contents of your ssmtp.conf file to include the following:</p><ul><li><strong>Outgoing mail server (SMTP server) or mailhub=</strong>smtp.gmail.com:587</li><li><strong>root=</strong>username@gmail.com</li><li><strong>AuthUser=</strong>your Gmail address(e.g.your_email@gmail.com)</li><li><strong>AuthPass=</strong>your Gmail <strong>app</strong> password</li></ul><p>Here is the <a href="https://support.google.com/mail/answer/185833?hl=en">link</a> to a resource on how to create a Gmail app password (click on $link to be taken to the guide). Make sure you have enabled 2FA on your Gmail account before proceeding to set up the app password. <a href="https://support.google.com/accounts/answer/185839?hl=en&amp;co=GENIE.Platform%3DDesktop"><strong>2FA setup guide.</strong></a></p><ul><li><strong>UseTLS=YES</strong></li><li><strong>UseSTARTTLS=YES</strong></li><li><strong>FromLineOverride=Yes (you can uncomment this at the bottom of the file).</strong></li><li>Leave the hostname as it is.</li></ul><p>After editing the file you should have this:</p><figure><img alt="Edited ssmtp configuration file." src="https://cdn-images-1.medium.com/max/746/1*1kFOolZVf-D6V6NVGgd-bw.png" /></figure><p>Type ctrl + O to write, click enter, and ctrl + x to exit the file.</p><p>Now you are all set to send emails from the command line. Use the command below to test it out.</p><pre><em>echo &quot;Testingclear!&quot; | mail -s &quot;Test Email&quot; your_email_address@gmail.com</em></pre><p>Echo command sends “Testingclear” as the body of the letter, -s specifies the subject of the letter (“Test Email”) followed by the email address.</p><figure><img alt="Testing email configuration." src="https://cdn-images-1.medium.com/max/804/1*y1AEWSqDEdqrxVm6G4QDhg.png" /></figure><p><strong>The email setup is done and working properly!!!!</strong></p><h4>NOTE:</h4><p>After you run the above command and it throws an error, Go through your configuration file again and make sure everything is correct. (There should be no space in between your app password characters).</p><p>Alternatively, you can use port 465 (SSL) in place of port 587 (TLS), all you have to do is change it to 465 and comment out UseSTARTTLS= YES as shown below:</p><pre>mailhub=smtp.gmail.com:465<br>#UseSTARTTLS=YES</pre><h3>Write a bash script to automate the task.</h3><p>Now it’s time to do the main work</p><p>Your bash script is going to create a log file, which includes the date and time the script was executed, as well as the details of your system&#39;s memory.</p><ol><li>Start by creating a dedicated folder to keep your script and log file.</li></ol><pre><em>mkdir memory_logs &amp;&amp; cd memory_logs</em></pre><p>2. Create a shell file using nano as shown below.</p><pre><em>nano memory_log.sh</em></pre><p>3. Indicate the absolute path to the bash executable (shebang)</p><pre><em>#!/bin/bash</em></pre><p>4. Start by assigning the variables needed.</p><pre><em>#path to the directory where the file should be created and used<br>path=/home/vagrant/memory_logs/log_file.log</em></pre><pre><em>#string formatting from date to extract hour and minute<br>midnight=$(date +%H%M)</em></pre><pre><em>#email address to receive the alert<br></em><a href="/service/mailto:email=clienttesting977@gmail.com"><em>email=**************@gmail.com</em></a></pre><p>5. Command to create the file</p><pre><em>touch ${path}</em></pre><pre><em>This command creates the log_file.log at the specified path. Notice how we call the path variable.</em></pre><p>6. Wrap it up using the conditionals</p><pre><em>if [[ ${midnight} == 0000 ]]; <br>   then echo &quot;HERE IS YOUR MIDNIGHT REPORT&quot; | mutt -a ${path} -s &quot;Midnight RAM Report&quot; -- ${email} &amp;&amp; sudo rm -f ${path}<br>else</em></pre><pre><em>date &gt;&gt; ${path}</em></pre><pre><em>free -h &gt;&gt; ${path}</em></pre><pre><em>echo &quot;-------&quot; &gt;&gt; ${path}</em></pre><pre><em>fi</em></pre><p><strong>Breakdown of the snippet:</strong></p><p>The if statement checks the midnight variable against 0000 which is the time at midnight, if the midnight variable equals 0000, then it sends an email containing the log file as an attachment to the email specified (already assigned to the email variable) with the subject of the email as “Midnight RAM Report”, the body of the message “HERE IS YOUR MIDNIGHT REPORT” and then proceeds to delete the log file and start recording afresh.</p><p>The mutt -a command used is to attach the log file gotten from the path variable.</p><pre><em>&amp;&amp; Sudo rm -f ${path}<br>#this part deletes the log file after it has been sent!</em></pre><p>The else statement executes when the initial condition is false i.e</p><pre><em>if [[ ${midnight} != 0000 ]];</em></pre><p>which means it only executes at hours that are not midnight (0000), it keeps on logging the date and system memory until its midnight before it is sent.</p><p>The echo “ — — — — “ serves as a delimiter of sorts and it is concluded by fi.</p><p>Now you can save and exit the file using ctrl + o, Enter, and ctrl + x.</p><p>It should all look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SB0BJaVikqWYW64m6yLoDg.png" /></figure><p>To make your script executable, Run:</p><pre>chmod u+x memory_log.sh</pre><p>Since our email and bash script have been set up, the last step is to use the crontab to schedule cronjobs to automate the execution of our bash script (hourly).</p><h3>Scheduling a cronjob for timely execution of the bash script.</h3><p>This is the easiest part, you can edit the crontab using the following command:</p><pre><em>$ crontab -e</em></pre><p>At the bottom of the file, add the following:</p><pre><em>0 * * * * bash /home/vagrant/memory_logs/memory_log.sh</em></pre><p>Save and exit the crontab. This command simply points to our bash script and instructs that it should be executed “At minute 0” of every hour of every day of the month.</p><p>Your email at midnight should look like this!</p><figure><img alt="Midnight RAM Report email photo" src="https://cdn-images-1.medium.com/max/904/1*VfIg9le4HPKmk7TiNKqu2g.png" /></figure><p>Congratulations, you have successfully created a bash script to send you daily RAM reports and also automate checking your system memory every hour.</p><h3>EXTRAS: TESTING YOUR SCRIPT.</h3><p>After setting up your bash scripts, email, and Crontab. You don’t need to wait till midnight to see if your script works, you can alter the crontab to something like:</p><p>* * * * * bash /home/vagrant/memory_logs/memory_log.sh</p><p>And in your script edit:</p><p>If [[ ${midnight} == 0000]] to if [[ ${midnight} == 1210]]</p><p>Explanation: what I did is I automated my script to run every minute and log system memory then instead of it to send the result at midnight (waiting too long) it will send it at 12:10 pm. This is a good way to see if your script is working perfectly.</p><p>Don’t forget to return it to the initial configuration after the test.</p><p>My time as of writing is 12:07 pm that’s why I used 1210 which means my script was executed and logged at 12:07 pm, 12:08 pm, and 12:09 pm, and then sent to my email and deleted at 12:10 pm.</p><p>Special thanks to <a href="https://medium.com/u/8141f14081e5">Abubakar Siddiq Ango </a>Your bash scripting tutorial helped a lot.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3bb4363f313" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Setup Ubuntu20.02-LTS using Vagrant on Linux OS]]></title>
            <link>https://medium.com/@cloudboy/how-to-setup-ubuntu20-02-lts-using-vagrant-on-linux-os-5e3e2788d326?source=rss-c37f87192bb8------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e3e2788d326</guid>
            <category><![CDATA[virtualbox]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[vagrant]]></category>
            <dc:creator><![CDATA[Modu Michael]]></dc:creator>
            <pubDate>Thu, 11 Aug 2022 00:12:27 GMT</pubDate>
            <atom:updated>2022-08-11T00:12:27.143Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is a guide to helping Linux users set up an Ubuntu environment on VirtualBox with the aid of vagrant. Vagrant is a tool for <strong>building and managing virtual machine environments in a single workflow. </strong>Vagrant enables an easy-to-use workflow and focuses on automation which lowers development environment setup time, increases production parity, and voids the “works on my machine” excuse. It helps you set up different environments on your machine without the need to fully transition to it.</p><h3>Installing VirtualBox from Ubuntu Repositories.</h3><p>This is the easiest way to install VirtualBox on Linux.</p><ol><li>Open up the terminal and run the update command.</li></ol><pre>sudo apt-get update</pre><p>2. Download and install VirtualBox directly by running:</p><pre>sudo apt-get install virtualbox</pre><p>3. The next step is to install the VirtualBox extension pack.</p><pre>sudo apt-get install virtualbox—ext–pack</pre><p>You are to read the VirtualBox Extension Pack Personal Use and Evaluation License and select <strong>&lt;Ok&gt;</strong> to confirm you understand. You have to move focus to the terminal window and then hit Tab to move the cursor to the &lt;Ok&gt; interface item and then hit Enter to proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*_bmWJ9lB54jSyBCymaNfcg.png" /><figcaption>Gotten from: <a href="https://phoenixnap.com/kb/install-virtualbox-on-ubuntu">https://phoenixnap.com/kb/install-virtualbox-on-ubuntu</a></figcaption></figure><p>4. Accept the terms of the VirtualBox PUEL license by moving the direction button to <strong>&lt;Yes&gt;</strong> and hitting <strong>Enter</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*6I0dSZ7zry-IKxbDXjjS9Q.png" /><figcaption>Gotten from: <a href="https://phoenixnap.com/kb/install-virtualbox-on-ubuntu">https://phoenixnap.com/kb/install-virtualbox-on-ubuntu</a></figcaption></figure><p>The output reads you have successfully installed “<strong>Oracle VM VirtualBox Extension Pack</strong>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*_D8_CNFk21YZOTl6DyJiZQ.png" /><figcaption>Gotten from: <a href="https://phoenixnap.com/kb/install-virtualbox-on-ubuntu">https://phoenixnap.com/kb/install-virtualbox-on-ubuntu</a></figcaption></figure><p>5. Open VirtualBox and create a new virtual environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*_FSdxXtwfMK-5crQcRmavA.png" /></figure><p>Set the memory size you want to allocate to the virtual machine. You can move the bar to alter the amount. (Green zone is a safe choice).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*gff5A0USfxiG3Gf_4sI2lQ.png" /></figure><p>Create a new hard disk or use an existing one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*hU-vCU72uEOQ7anISTPlKA.png" /></figure><p>Specify the type of file you want to use for the new virtual machine. The disk image is to be used here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*h2EWk7LZFdnDs8QqmYlQ4Q.png" /></figure><p>Choose how the storage is managed on your VM. (Dynamically allocated is recommended)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*SegzmlH72Mtof9dh9_6Fpg.png" /></figure><p>Finally, Specify the name and location where you want to create the file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*XSXeIMKaPDv_B2543UZ3UQ.png" /></figure><p>Tap on create and the virtual machine will be created, next step is to install <strong>Vagrant.</strong></p><h3>Installing Vagrant on Linux OS.</h3><ol><li>You can install vagrant for your Linux distro by going to the official <a href="https://www.vagrantup.com/downloads">vagrant website</a>.</li><li>Select the Linux distro you are using:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*1y9NS7_IPr3XsJTGgrlk7w.png" /><figcaption>Different Linux Distros and respective commands.</figcaption></figure><p>Copy and paste the commands line by line in your terminal and wait for Vagrant to be completely installed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*OWfapxWY04gz1_QqNpHzYw.png" /><figcaption>The above is an example of the commands to install vagrant on Fedora.</figcaption></figure><p>3. Create a dedicated folder to house the vagrant files and open it on the terminal. E.g</p><pre>cd ubuntu20.04-LTS</pre><p>4. Initialize your machine using:</p><pre>vagrant init ubuntu/focal64</pre><p>A vagrant file will be created to store the configuration for your machine. Ubuntu/focal64 is the vagrant box for ubuntu20.04-LTS.</p><p>5. The next step is to get the ubuntu OS via a Vagrant box.</p><pre>vagrant up</pre><p>The above command checks first to see if the machine already has a sample of the OS image before proceeding to download the box from the vagrant registry. On completion, Vagrant automatically creates the virtual machine using your specified configurations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*GsE9mbNPAoPvWDA89Mv-Dw.png" /></figure><p>6. Login into the machine by typing</p><pre>vagrant ssh</pre><p>Voila! Ubuntu20.04-LTS has been successfully installed on your virtual machine and you are ready to go.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e3e2788d326" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>