<?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"><channel><title><![CDATA[DevOps_Journey_4]]></title><description><![CDATA[DevOps_Journey_4]]></description><link>https://devopsjourney4.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 10:30:43 GMT</lastBuildDate><atom:link href="https://devopsjourney4.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The Power of Shell Scripting in DevOps]]></title><description><![CDATA[What is Shell Scripting?
Shell scripting is writing a series of commands for the Unix/Linux shell to automate repetitive tasks. Think of it as a lightweight, quick-to-execute programming language tailor-made for system-level automation.
Shells common...]]></description><link>https://devopsjourney4.hashnode.dev/the-power-of-shell-scripting-in-devops</link><guid isPermaLink="true">https://devopsjourney4.hashnode.dev/the-power-of-shell-scripting-in-devops</guid><category><![CDATA[shell script]]></category><category><![CDATA[Devops]]></category><category><![CDATA[#AWS #AutoScaling #CloudComputing #DevOps #AWSCloud #Scalability #CloudInfrastructure #AWSDevOps #AutoScalingGroups #ElasticLoadBalancer #EC2 #CloudOptimization #TechBlog #AWSBlog #DevOpsBlog #HighAvailability #CloudManagement #InfrastructureAsCode #AWSArchitecture #CloudAutomation #CostOptimization]]></category><category><![CDATA[operating system]]></category><dc:creator><![CDATA[M Chidrup]]></dc:creator><pubDate>Fri, 23 May 2025 16:45:35 GMT</pubDate><content:encoded><![CDATA[<h3 id="heading-what-is-shell-scripting">What is Shell Scripting?</h3>
<p>Shell scripting is writing a series of commands for the Unix/Linux shell to automate repetitive tasks. Think of it as a lightweight, quick-to-execute programming language tailor-made for system-level automation.</p>
<p><strong>Shells commonly used:</strong></p>
<ul>
<li><p><code>bash</code> (Bourne Again SHell)</p>
</li>
<li><p><code>sh</code> (Bourne Shell)</p>
</li>
<li><p><code>zsh</code>, <code>ksh</code>, and more…</p>
</li>
</ul>
<hr />
<h3 id="heading-why-shell-scripting-matters-in-devops">⚙️ Why Shell Scripting Matters in DevOps</h3>
<p>In a DevOps workflow, automation is key. Here’s where shell scripts become indispensable:</p>
<ul>
<li><p>✅ <strong>CI/CD Automation</strong>: Automate build, test, and deploy processes.</p>
</li>
<li><p>✅ <strong>Server Setup &amp; Configuration</strong>: Install packages, configure firewalls, set permissions.</p>
</li>
<li><p>✅ <strong>Log Monitoring &amp; Alerts</strong>: Tail logs, grep for errors, send notifications.</p>
</li>
<li><p>✅ <strong>Backup and Cleanup Jobs</strong>: Scheduled scripts using <code>cron</code>.</p>
</li>
</ul>
<hr />
<h3 id="heading-a-simple-example">🖥️ A Simple Example</h3>
<pre><code class="lang-plaintext">bash
CopyEdit#!/bin/bash
# deploy.sh - A sample deployment script

echo "Starting deployment..."
git pull origin main
npm install
pm2 restart myapp

echo "Deployment complete ✅"
</code></pre>
<p>This basic script can be part of a post-merge hook or manually triggered after a feature is merged into the main branch.</p>
<hr />
<h3 id="heading-best-practices">🔒 Best Practices</h3>
<ol>
<li><p><strong>Use</strong> <code>set -e</code> to exit on any error.</p>
</li>
<li><p><strong>Log everything</strong> — redirect output to a log file.</p>
</li>
<li><p><strong>Use functions</strong> to modularize code.</p>
</li>
<li><p><strong>Parameterize</strong> — use arguments and flags.</p>
</li>
<li><p><strong>Test your scripts</strong> — especially destructive ones.</p>
</li>
</ol>
<hr />
<h3 id="heading-tools-to-pair-with-shell-scripts">🛠️ Tools to Pair with Shell Scripts</h3>
<ul>
<li><p><strong>cron</strong> – Schedule script execution</p>
</li>
<li><p><strong>Ansible</strong> – Combine YAML and shell for idempotent automation</p>
</li>
<li><p><strong>Docker</strong> – Entry scripts for container initialization</p>
</li>
<li><p><strong>Jenkins</strong> – Run shell scripts in build steps</p>
</li>
</ul>
<hr />
<h3 id="heading-real-life-use-case-automating-aws-ec2-backup">🚀 Real-Life Use Case: Automating AWS EC2 Backup</h3>
<pre><code class="lang-plaintext">bash
CopyEdit#!/bin/bash
INSTANCE_ID="i-0abcd1234efgh5678"
DATE=$(date +%F)
aws ec2 create-image --instance-id $INSTANCE_ID --name "Backup-$DATE" --no-reboot
</code></pre>
<p>Automating AWS backups can be as simple as this script scheduled via <code>cron</code>.</p>
<p>#!/bin/bash</p>
<h1 id="heading-create-a-new-directory">Create a new directory</h1>
<p>mkdir my_directory echo "Directory 'my_directory' created."</p>
<h1 id="heading-change-into-the-new-directory">Change into the new directory</h1>
<p>cd my_directory echo "Changed to directory 'my_directory'."</p>
<h1 id="heading-create-a-new-file-using-touch">Create a new file using touch</h1>
<p>touch myfile.txt echo "File 'myfile.txt' created."</p>
<h1 id="heading-list-files-in-the-current-directory">List files in the current directory</h1>
<p>ls echo "Listed all files in the current directory."</p>
<h1 id="heading-show-present-working-directory">Show present working directory</h1>
<p>pwd echo "Displayed current working directory."</p>
<h1 id="heading-write-content-to-file-using-echo-and-redirect">Write content to file using echo and redirect</h1>
<p>echo "This is a test file." &gt; myfile.txt echo "Content written to 'myfile.txt'."</p>
<h1 id="heading-display-content-of-the-file">Display content of the file</h1>
<p>cat myfile.txt echo "Displayed content of 'myfile.txt'."</p>
<h1 id="heading-show-disk-usage-in-human-readable-format">Show disk usage in human-readable format</h1>
<p>df -h echo "Displayed disk usage."</p>
<h1 id="heading-show-memory-usage">Show memory usage</h1>
<p>free -m echo "Displayed memory usage in MB."</p>
<h1 id="heading-show-number-of-cpu-cores">Show number of CPU cores</h1>
<p>nproc echo "Displayed number of CPU cores."</p>
]]></content:encoded></item></channel></rss>