<?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[90DAYSOFDEVOPS]]></title><description><![CDATA[90DAYSOFDEVOPS]]></description><link>https://belwalrakshita08.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 18 Jun 2026 03:19:59 GMT</lastBuildDate><atom:link href="https://belwalrakshita08.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Python Libraries for Data Cleaning: Pandas & NumPy]]></title><description><![CDATA[A Real-World Story: From Messy Logs to Meaningful Insights
A data analyst once received 2 GB of messy CSV logs from a retail store; half of them had missing prices, mixed date formats, and duplicated entries. The manager wanted insights by tomorrow m...]]></description><link>https://belwalrakshita08.hashnode.dev/python-libraries-for-data-cleaning-pandas-and-numpy</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/python-libraries-for-data-cleaning-pandas-and-numpy</guid><category><![CDATA[Python]]></category><category><![CDATA[Data Science]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[AI]]></category><category><![CDATA[learning]]></category><category><![CDATA[Machine Learning]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Thu, 13 Nov 2025 16:47:53 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1763052115097/7d761c8b-5bb1-42fb-8268-d4e49b2b8b43.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-a-real-world-story-from-messy-logs-to-meaningful-insights">A Real-World Story: From Messy Logs to Meaningful Insights</h3>
<p>A data analyst once received 2 GB of messy CSV logs from a retail store; half of them had missing prices, mixed date formats, and duplicated entries. The manager wanted insights <em>by tomorrow morning</em>.</p>
<p>Instead of panicking, the analyst opened up their Python notebook, imported <strong>Pandas</strong> and <strong>NumPy</strong>, and started cleaning. Within hours, they had a structured, usable dataset that revealed sales patterns the business had never seen before.</p>
<p>That’s the power of <strong>Python for data cleaning</strong>; it turns chaos into clarity.</p>
<p>💼 <strong>Follow me on</strong> <a target="_blank" href="https://www.linkedin.com/in/rakshitabelwal/"><strong>LinkedIn</strong></a> for insights, stories, and reflections on my learning journey.<br />🐦 <strong>Follow me on</strong> <a target="_blank" href="https://x.com/rakshitabelwal"><strong>Twitter</strong></a> <a target="_blank" href="https://x.com/rakshitabelwal"></a>for short, bite-sized thoughts and daily tech learnings.</p>
<h2 id="heading-why-data-cleaning-matters">Why Data Cleaning Matters</h2>
<p>Before you can analyse or visualise, your data needs to make sense.<br />Imagine trying to compute “average sales” when half your dataset has missing or wrong numbers; the results would mislead you completely.</p>
<p>That’s where libraries like <strong>Pandas</strong> and <strong>NumPy</strong> shine.<br />They give you the tools to:</p>
<ul>
<li><p>Handle missing data.</p>
</li>
<li><p>Fix inconsistent formats.</p>
</li>
<li><p>Remove duplicates.</p>
</li>
<li><p>Transform raw data into a structured form.</p>
</li>
</ul>
<p>Let’s explore how they help you do this - step by step.</p>
<h2 id="heading-pandas-the-data-cleaning-workhorse">🐼 Pandas: The Data Cleaning Workhorse</h2>
<p>If Python had a cleaning superhero, it would be <strong>Pandas</strong>.<br />It’s built on top of NumPy and makes working with tabular data (like Excel or CSV) incredibly simple.</p>
<h3 id="heading-key-features">Key Features</h3>
<ul>
<li><p><strong>DataFrame</strong>: A table-like structure with rows and columns</p>
</li>
<li><p><strong>Easy I/O</strong>: Read and write from CSV, Excel, SQL, JSON</p>
</li>
<li><p><strong>Built-in cleaning functions</strong>: <strong>dropna(), fillna(), replace()</strong>, and more</p>
</li>
</ul>
<h3 id="heading-example-handling-missing-data"><strong>Example: Handling Missing Data</strong></h3>
<p><code>import pandas as pd</code></p>
<p><code>#Load data</code></p>
<p><code>df =</code> <a target="_blank" href="http://pd.read"><code>pd.read</code></a><code>_csv("sales.csv")</code></p>
<p><code>#Check missing values</code></p>
<p><code>print(df.isnull().sum())</code></p>
<p><code>#Fill missing values</code></p>
<p><code>df['price'].fillna(df['price'].mean(), inplace=True)</code></p>
<p><code>#Remove duplicates</code></p>
<p><code>df.drop_duplicates(inplace=True)</code></p>
<p><strong>What’s happening here:</strong></p>
<ul>
<li><p>We’re identifying missing values.</p>
</li>
<li><p>Replacing them with the mean of the column.</p>
</li>
<li><p>Removing duplicate rows.</p>
</li>
</ul>
<p>A once-messy CSV now becomes a clean, reliable dataset ready for analysis.</p>
<h3 id="heading-pro-tips-for-pandas">Pro Tips for Pandas</h3>
<p>✅ Always start with <a target="_blank" href="http://df.info"><code>df.info</code></a><code>()</code> and <code>df.describe()</code>, they reveal data types and missing patterns.<br />✅ Use <code>df.rename(columns={})</code> to keep column names consistent.<br />✅ Convert date columns using <a target="_blank" href="http://pd.to"><code>pd.to</code></a><code>_datetime()</code> for easy filtering and sorting.</p>
<h2 id="heading-numpy-the-backbone-of-data-computation">🔢 NumPy: The Backbone of Data Computation</h2>
<p>While Pandas is great for tables, <strong>NumPy</strong> excels at fast and efficient numerical operations, the foundation of almost every Python data science library.</p>
<h3 id="heading-why-its-great-for-cleaning">Why It’s Great for Cleaning</h3>
<ul>
<li><p>Works efficiently with large datasets.</p>
</li>
<li><p>Helps normalise or standardise numeric data.</p>
</li>
<li><p>Handles missing or invalid numbers gracefully.</p>
</li>
</ul>
<h3 id="heading-example-dealing-with-outliers"><strong>Example: Dealing with Outliers</strong></h3>
<p><code>import numpy as np</code></p>
<p><code>data = np.array([10, 12, 11, 300, 13, 15, 14])</code></p>
<p><code>#Calculate mean and standard deviation</code></p>
<p><code>mean = np.mean(data) std = np.std(data)</code></p>
<p><code>#Filter out values beyond 2 std deviations</code></p>
<p><code>filtered_data = data[np.abs(data - mean) &lt; 2 * std]</code></p>
<p><code>print(filtered_data)</code></p>
<p>This code removes extreme values (outliers) that could skew your results.</p>
<h3 id="heading-pro-tips-for-numpy">Pro Tips for NumPy</h3>
<p>✅ Use <code>np.isnan()</code> to handle NaN values efficiently.<br />✅ Leverage <strong>vectorised operations</strong> instead of loops for faster performance.<br />✅ Combine with Pandas: clean using Pandas, then process numerically with NumPy.</p>
<h2 id="heading-pandas-numpy-data-cleaning-powerhouse">Pandas + NumPy = Data Cleaning Powerhouse</h2>
<p>In practice, you’ll often use them together.<br />Here’s a mini real-world example:</p>
<p><code>import pandas as pd</code></p>
<p><code>import numpy as np</code></p>
<p><code>df =</code> <a target="_blank" href="http://pd.read"><code>pd.read</code></a><code>_csv("data.csv")</code></p>
<p><code>#Replace missing numeric values with column median</code></p>
<p><code>df['age'] = df['age'].replace(np.nan, df['age'].median())</code></p>
<p><code>#Normalize numerical column</code></p>
<p><code>df['salary'] = (df['salary'] - np.mean(df['salary'])) / np.std(df['salary'])</code></p>
<p><code>#Drop duplicates and reset index</code></p>
<p><code>df = df.drop_duplicates().reset_index(drop=True)</code></p>
<p>In just a few lines, you’ve:<br />✔️ Handled missing values<br />✔️ Standardised salary data<br />✔️ Cleaned duplicates</p>
<p>This combination forms the backbone of any serious data-prep workflow in Python.</p>
<h2 id="heading-best-practices-for-clean-reliable-data">💡 Best Practices for Clean, Reliable Data</h2>
<p>✅ <strong>Always visualize missing data</strong> - tools like <code>seaborn.heatmap(df.isnull())</code> help.<br />✅ <strong>Document every cleaning step</strong> - reproducibility is key in data work.<br />✅ <strong>Validate results</strong> - check means, counts, and unique values after cleaning.<br />✅ <strong>Automate repetitive cleaning tasks</strong> - small scripts save hours in the long run.</p>
<h2 id="heading-references">📚 References</h2>
<ul>
<li><p><a target="_blank" href="https://pandas.pydata.org/docs/">Pandas Official Documentation</a></p>
</li>
<li><p><a target="_blank" href="https://numpy.org/doc/stable/user/index.html">NumPy User Guide</a></p>
</li>
<li><p><a target="_blank" href="https://realpython.com/python-data-cleaning-numpy-pandas/">Real Python: Cleaning Data With Pandas</a></p>
</li>
</ul>
<h2 id="heading-community-corner">🤝 Community Corner</h2>
<p>Data cleaning can sometimes feel like detective work - uncovering clues, testing assumptions, and fixing hidden errors.</p>
<p>What’s the messiest dataset you’ve ever cleaned?<br />Or what trick helped you handle missing values efficiently?</p>
<p>💬 Share your story or favourite <strong>Pandas/NumPy trick</strong> in the comments, your experience might save someone else’s late-night debugging session!</p>
<h2 id="heading-faq-data-cleaning-in-python">❓ FAQ: Data Cleaning in Python</h2>
<p><strong>1. What’s the difference between Pandas and NumPy?</strong><br />Pandas handles structured tabular data; NumPy handles numerical arrays and math operations.</p>
<p><strong>2. Is Pandas built on top of NumPy?</strong><br />Yes, Pandas uses NumPy under the hood for fast numerical processing.</p>
<p><strong>3. Can I clean large datasets with Pandas?</strong><br />Yes, but for very large data, consider using <strong>Dask</strong> or <strong>PySpark</strong> for scalability.</p>
<p><strong>4. How do I handle missing values?</strong><br />Use <code>dropna()</code>, <code>fillna()</code>, or replace them with averages, medians, or a constant.</p>
<p><strong>5. What’s the best way to remove duplicates?</strong><br />Use <code>df.drop_duplicates()</code> and verify with <code>df.duplicated().sum()</code>.</p>
<p><strong>6. How can I handle inconsistent data types?</strong><br />Use <code>astype()</code> to convert columns into consistent formats (e.g., strings to integers).</p>
<p><strong>7. Should I clean data before visualisation?</strong><br />Absolutely! Clean data ensures your visualisations and insights are accurate.</p>
<p><strong>8. Do I need both Pandas and NumPy?</strong><br />Most of the time, yes — Pandas for structure, NumPy for speed and numeric accuracy.</p>
<h3 id="heading-lets-connect-and-keep-the-conversation-going">🌐 Let’s Connect and Keep the Conversation Going</h3>
<p>If you enjoyed this article and want to explore more about <strong>Python, AI, and DevOps</strong>, let’s connect!</p>
<p>💼 <strong>Follow me on</strong> <a target="_blank" href="https://www.linkedin.com/in/rakshitabelwal/"><strong>LinkedIn</strong></a> for insights, stories, and reflections on my learning journey.<br />🐦 <strong>Follow me on</strong> <a target="_blank" href="https://x.com/rakshitabelwal"><strong>Twitter</strong></a> <a target="_blank" href="https://x.com/rakshitabelwal"></a>for short, bite-sized thoughts and daily tech learnings.</p>
<p>Let’s learn, build, and grow - one Python script at a time. 💻✨</p>
]]></content:encoded></item><item><title><![CDATA[Azure Cognitive Services Explained in 5 Real-World Examples]]></title><description><![CDATA[What if AI were just an API call away?

When I first discovered Azure Cognitive Services, I was blown away by how easy Microsoft made it to add AI features into any app, without needing a PhD in machine learning.
As someone coming from a Cloud & DevO...]]></description><link>https://belwalrakshita08.hashnode.dev/azure-cognitive-services-explained-in-5-real-world-examples</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/azure-cognitive-services-explained-in-5-real-world-examples</guid><category><![CDATA[Azure]]></category><category><![CDATA[Devops]]></category><category><![CDATA[AI]]></category><category><![CDATA[Machine Learning]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Tue, 11 Nov 2025 04:35:29 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1762835376027/2c529a9a-c0b5-4c4e-818e-b4f9733b7cdb.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-what-if-ai-were-just-an-api-call-away">What if AI were just an API call away?</h3>
<hr />
<p>When I first discovered <strong>Azure Cognitive Services</strong>, I was blown away by how easy Microsoft made it to add AI features into any app, without needing a PhD in machine learning.</p>
<p>As someone coming from a <strong>Cloud &amp; DevOps</strong> background, AI once felt like a black box. But Cognitive Services changed that perception. It made me realise that AI isn’t just for data scientists, it’s for every developer who wants to build smarter apps.</p>
<p>So, let’s explore <strong>five examples</strong> that bring Azure Cognitive Services to life.</p>
<h2 id="heading-what-are-azure-cognitive-services">What Are Azure Cognitive Services?</h2>
<p>In simple terms, <strong>Azure Cognitive Services</strong> is a collection of pre-built AI models by Microsoft that help apps <strong>see, hear, speak, understand, and decide</strong>.</p>
<p>You can think of it as <strong><em>plug-and-play AI</em>.</strong><br />You send data → Azure’s trained model analyses it → you get a smart response.</p>
<p>It’s divided into five key areas:</p>
<ul>
<li><p><strong>Vision</strong> 👁️ (Image and video understanding)</p>
</li>
<li><p><strong>Speech</strong> 🗣️ (Speech-to-text, text-to-speech, and translation)</p>
</li>
<li><p><strong>Language</strong> 📝 (Text analytics, sentiment, and translation)</p>
</li>
<li><p><strong>Decision</strong> 🧮 (Anomaly detection, personalisation, moderation)</p>
</li>
<li><p><strong>Search</strong> 🔍 (Contextual web, video, and image search)</p>
</li>
</ul>
<hr />
<p>🌟 You can connect with me on <a target="_blank" href="https://www.linkedin.com/in/rakshitabelwal/"><strong>LinkedIn</strong></a> <strong>and</strong> <a target="_blank" href="https://x.com/rakshitabelwal"><strong>Twitter</strong></a> to have more discussion!</p>
<h2 id="heading-example-1-face-recognition-with-the-vision-api">Example 1: Face Recognition with the Vision API</h2>
<p>Imagine you’re building a secure door-access app. Instead of typing passwords, users can simply look at the camera.</p>
<p>That’s possible using the <strong>Face API</strong> in Cognitive Services.</p>
<p>With a few lines of code, you can detect:</p>
<ul>
<li><p>Who’s in the image</p>
</li>
<li><p>Their emotions (happy, angry, surprised)</p>
</li>
<li><p>Even match them with stored profiles</p>
</li>
</ul>
<p><strong>Pro Tip:</strong> Always handle biometric data carefully, use encryption and follow compliance best practices like GDPR.</p>
<p><strong>Best Use Cases:</strong></p>
<ul>
<li><p>Attendance systems</p>
</li>
<li><p>Smart photo albums</p>
</li>
<li><p>Emotion-based customer analysis</p>
</li>
</ul>
<p>📘 <a target="_blank" href="https://learn.microsoft.com/en-us/azure/ai-services/computer-vision/overview-identity?utm_source=chatgpt.com">Learn more about Azure Face API</a></p>
<hr />
<h2 id="heading-example-2-speech-to-text-for-hands-free-apps">Example 2: Speech-to-Text for Hands-Free Apps</h2>
<p>Have you ever dictated a message using your phone? That’s exactly what <strong>Speech-to-Text API</strong> can do, but for your own app.</p>
<p>In one of my side projects, I integrated this service into a Python-based voice assistant. It converted spoken words into text in real-time, and the accuracy surprised me.</p>
<p><strong>Best Practices:</strong></p>
<ul>
<li><p>Use the correct locale (e.g., <code>en-IN</code>, <code>en-US</code>) for better accuracy.</p>
</li>
<li><p>Test with diverse voice samples to reduce bias.</p>
</li>
</ul>
<p><strong>Best Use Cases:</strong></p>
<ul>
<li><p>Meeting transcription tools</p>
</li>
<li><p>Voice-driven chatbots</p>
</li>
<li><p>Accessibility apps</p>
</li>
</ul>
<p>📘 <a target="_blank" href="https://learn.microsoft.com/en-us/azure/ai-services/speech-service/">Azure Speech Service documentation</a></p>
<hr />
<h2 id="heading-example-3-real-time-language-translation">Example 3: Real-Time Language Translation</h2>
<p>The <strong>Translator API</strong> helps break language barriers by translating text or speech into 70+ languages.</p>
<p>Imagine a global e-commerce website where you can instantly translate product reviews or chat messages.</p>
<p><strong>Developer Tip:</strong><br />Use <strong>custom translation</strong> to fine-tune model accuracy for domain-specific terms (like medical or legal vocabulary).</p>
<p><strong>Best Use Cases:</strong></p>
<ul>
<li><p>Multilingual chat systems</p>
</li>
<li><p>Global product reviews</p>
</li>
<li><p>Educational apps for language learners</p>
</li>
</ul>
<hr />
<h2 id="heading-example-4-text-analytics-for-sentiment-amp-insights">Example 4: Text Analytics for Sentiment &amp; Insights</h2>
<p>If you’re analysing tweets or customer reviews, the <strong>Text Analytics API</strong> can instantly tell you whether the feedback is positive, negative, or neutral.</p>
<p>In one of my DevOps automation dashboards, I used it to analyse incident tickets, identifying which were marked with frustration words (“urgent”, “broken”, “down”) to prioritise alerts.</p>
<p><strong>Best Practices:</strong></p>
<ul>
<li><p>Pre-clean text to remove URLs and symbols.</p>
</li>
<li><p>Combine with <strong>Power BI</strong> for real-time visualisations.</p>
</li>
</ul>
<p><strong>Best Use Cases:</strong></p>
<ul>
<li><p>Customer feedback analysis</p>
</li>
<li><p>Social media sentiment tracking</p>
</li>
<li><p>Ticket prioritization</p>
</li>
</ul>
<hr />
<h2 id="heading-example-5-content-moderation-for-safe-communities">Example 5: Content Moderation for Safe Communities</h2>
<p>In community platforms, keeping harmful content away is vital. The <strong>Content Moderator API</strong> uses machine learning to detect profanity, adult content, and personally identifiable information (PII).</p>
<p>Think of it as your digital bouncer for text, images, or videos.</p>
<p><strong>Pro Tip:</strong> Combine automated moderation with human review for best accuracy.</p>
<p><strong>Best Use Cases:</strong></p>
<ul>
<li><p>Online forums and chat apps</p>
</li>
<li><p>Comment moderation tools</p>
</li>
<li><p>Social media platforms</p>
</li>
</ul>
<p>📘 <a target="_blank" href="https://learn.microsoft.com/en-us/azure/ai-services/content-moderator/overview">Azure Content Moderator</a></p>
<hr />
<h2 id="heading-best-practices-when-using-cognitive-services">Best Practices When Using Cognitive Services</h2>
<ul>
<li><p>Start small, test one API at a time.</p>
</li>
<li><p>Secure your keys and endpoints with Azure Key Vault.</p>
</li>
<li><p>Monitor usage in <strong>Azure Portal</strong> using metrics and alerts.</p>
</li>
<li><p>Leverage <strong>Azure AI Studio</strong> to visualise, test, and fine-tune your models.</p>
</li>
<li><p>Always consider data privacy and ethical AI practices.</p>
</li>
</ul>
<hr />
<h2 id="heading-community-corner-lets-talk">🤝 Community Corner: Let’s Talk!</h2>
<p>What’s the coolest AI feature you’ve built (or dream of building) using Azure Cognitive Services?</p>
<p>Drop your ideas or questions in the comments - I’d love to hear how you’re using AI to make your apps smarter.<br />You can also connect with me on <a target="_blank" href="https://www.linkedin.com/in/rakshitabelwal/"><strong>LinkedIn</strong></a> <strong>and</strong> <a target="_blank" href="https://x.com/rakshitabelwal"><strong>Twitter</strong></a> to continue the discussion!</p>
<hr />
<h2 id="heading-faq-azure-cognitive-services-for-beginners">❓ FAQ: Azure Cognitive Services for Beginners</h2>
<p><strong>1. Is Azure Cognitive Services free to start with?</strong><br />Yes! Microsoft offers a free tier with limited transactions for most APIs.</p>
<p><strong>2. Do I need AI/ML experience?</strong><br />Not at all. These are pre-trained models; no data science background required.</p>
<p><strong>3. How do I authenticate the APIs?</strong><br />Use the API key and endpoint provided in the Azure Portal.</p>
<p><strong>4. Can I integrate these APIs with Python or Node.js?</strong><br />Yes, SDKs are available for multiple languages, including Python, C#, Java, and JavaScript.</p>
<p><strong>5. Are Cognitive Services available globally?</strong><br />Yes, Azure has global regions, but always choose the one closest to your users for low latency.</p>
<p><strong>6. How secure is the data I send?</strong><br />All data is encrypted in transit and at rest. You can also choose to store or not store processed data.</p>
<p><strong>7. Can I customise or retrain models?</strong><br />Yes, some services (like Custom Vision or Translator) let you train models with your own data.</p>
<p><strong>8. What’s the difference between Cognitive Services and Azure AI Studio?</strong><br />Cognitive Services are APIs; AI Studio helps you visualise, test, and integrate those APIs easily.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Day 14 Task:  Create a Linux & Git-GitHub Cheat Sheet]]></title><description><![CDATA[LINUX COMMANDS CHEAT SHEET
Directory Navigation

ls = list files and directories in current directory

ls -a = list all files and directories including hidden files.

ls -l = list files and directories in long format.

pwd = shows the present working...]]></description><link>https://belwalrakshita08.hashnode.dev/day-14-task-create-a-linux-git-github-cheat-sheet</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/day-14-task-create-a-linux-git-github-cheat-sheet</guid><category><![CDATA[#90daysofdevops]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Linux]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Git]]></category><category><![CDATA[cheatsheet]]></category><category><![CDATA[shell script]]></category><category><![CDATA[#TWS]]></category><category><![CDATA[Hashnode]]></category><category><![CDATA[linux-commands]]></category><category><![CDATA[Gitcommands]]></category><category><![CDATA[LinkedIn]]></category><category><![CDATA[learning]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Fri, 23 Aug 2024 16:47:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1724431322100/64875d1b-14c8-4fbf-a543-3e8dd382bb92.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-linux-commands-cheat-sheet"><strong><mark>LINUX COMMANDS CHEAT SHEET</mark></strong></h3>
<h3 id="heading-directory-navigation"><strong>Directory Navigation</strong></h3>
<ul>
<li><p><code>ls</code> = list files and directories in current directory</p>
</li>
<li><p><code>ls -a</code> = list all files and directories including hidden files.</p>
</li>
<li><p><code>ls -l</code> = list files and directories in long format.</p>
</li>
<li><p><code>pwd</code> = shows the present working directory.</p>
</li>
<li><p><code>cd [dir_path]</code> = change location to specified directory.</p>
</li>
<li><p><code>cd ~</code> = directory to $HOME.</p>
</li>
<li><p><code>cd ..</code> = move up one directory level.</p>
</li>
</ul>
<h3 id="heading-files"><strong>Files</strong></h3>
<ul>
<li><p><code>mkdir [dir_name]</code>\= create a new directory.</p>
</li>
<li><p><code>rm [file_name]</code>\= remove a file.</p>
</li>
<li><p><code>rm -r [directory_name]</code>\= remove a directory recursively.</p>
</li>
<li><p><code>cp [source_file] [destination_file]</code>\= copy the contents of one file to another file.</p>
</li>
<li><p><code>mv [source_file] [destination_file]</code>\= move or rename files or directories.</p>
</li>
<li><p><code>touch [file_name]</code>\= create a new file.</p>
</li>
<li><p><code>cat [file_name]</code>\= show the contents of a file.</p>
</li>
<li><p><code>cat [source_file] &gt;&gt; [destination_file]</code>\= append file contents to another file.</p>
</li>
<li><p><code>nano [file_name]</code>\= open or create a file using the nano text editor.</p>
</li>
<li><p><code>vi [file_name]</code>, <code>vim [file_name]</code>\= open or create a file using the Vi/Vim text editor.</p>
</li>
<li><p><code>head [file_name]</code> = show the first ten lines of a file.</p>
</li>
<li><p><code>tail [file_name]</code>\= show the last ten lines of a file.</p>
</li>
</ul>
<h3 id="heading-users-and-groups"><strong>Users and Groups</strong></h3>
<ul>
<li><p><code>sudo useradd [user_name]</code>\= Create a new user account.</p>
</li>
<li><p><code>sudo userdel [user_name</code>\= Delete a user account.</p>
</li>
<li><p><code>sudo usermod -aG [group_name] [user_name]</code>\= Modify user information (add a user to a group).</p>
</li>
<li><p><code>sudo passwd [user_name</code>\= Change the current user's or another user's password.</p>
</li>
<li><p><code>sudo groupadd [group_name]</code>\= Add a new group.</p>
</li>
<li><p><code>sudo groupdel [group_name]</code>\= Delete a group.</p>
</li>
<li><p><code>sudo [command]</code>\= Temporarily elevate user privileges to superuser or root.</p>
</li>
<li><p><code>su - [user_name]</code>\= Switch the user account or become a superuser.</p>
</li>
</ul>
<h3 id="heading-file-permissions"><strong>File Permissions</strong></h3>
<ul>
<li><p><code>chmod 777 [file_name]</code>\= Assign read, write, and execute file permission to everyone (rwxrwxrwx).</p>
</li>
<li><p><code>chown [user_name] [file_name]</code>\= Change the ownership of a file with chown command.</p>
</li>
<li><p><code>chown [user_name]:[group_name] [file_name]</code>\= Change the owner and group ownership of a file.</p>
</li>
<li><p><code>chgrp [group_name] [file/directory]</code>\= Change file or directory group.</p>
</li>
</ul>
<h3 id="heading-processes"><strong>Processes</strong></h3>
<ul>
<li><p><code>ps</code>\= List active processes.</p>
</li>
<li><p><code>top</code>\= See all running processes</p>
</li>
<li><p><code>htop</code>\= Interactive and colorful process viewer.</p>
</li>
<li><p><code>kill [process_id]</code>\= Terminate a Linux process under a given ID.</p>
</li>
<li><p><code>killall [label]</code>\= Terminate all processes with a given label.</p>
</li>
<li><p><code>nohup [command] &amp;</code>\= Run a Linux process in the background.</p>
</li>
<li><p><code>bg</code>\= List and resume stopped jobs in the background.</p>
</li>
<li><p><code>fg</code>\= Bring the most recently suspended job to the foreground.</p>
</li>
<li><p><code>fg [job]</code>\= Bring a particular job to the foreground.</p>
</li>
</ul>
<h3 id="heading-system-management"><strong>System Management</strong></h3>
<ul>
<li><p><code>uptime</code>\= Display how long the system has been running, including the load average.</p>
</li>
<li><p><code>hostname</code>\= View system hostname</p>
</li>
<li><p><code>hostname -i</code>\= Show the IP address of the system</p>
</li>
<li><p><code>date</code>\= See current date and time.</p>
</li>
<li><p><code>cal</code>\= Show current calendar (month and day).</p>
</li>
<li><p><code>whoami</code>\= See which user you are using.</p>
</li>
</ul>
<h3 id="heading-network"><strong>Network</strong></h3>
<ul>
<li><p><code>ifconfig</code>\= Display IP addresses of all network interfaces.</p>
</li>
<li><p><code>ping [remote_host]</code>\= Ping remote host.</p>
</li>
<li><p><code>netstat</code>\= Show network statistics.</p>
</li>
<li><p><code>nslookup [domain_name]</code>\= Receive information about an internet domain.</p>
</li>
</ul>
<h3 id="heading-ssh-login"><strong>SSH Login</strong></h3>
<ul>
<li><p><code>ssh [user_name]@[host]</code>\= Connect to a remote host as a user via SSH.</p>
</li>
<li><p><code>ssh [host]</code>\= Securely connect to a host via SSH default port 22.</p>
</li>
<li><p><code>ssh-keygen</code>\= Generate SSH key pairs</p>
</li>
<li><p><code>scp [file_name] [user_name]@[host]:[rem ote_path]</code>\= Securely copy files between local and remote systems via SSH.</p>
</li>
</ul>
<h3 id="heading-disk-usage"><strong>Disk Usage</strong></h3>
<ul>
<li><p><code>df -h</code>\= Check free and used space on mounted systems.</p>
</li>
<li><p><code>mount</code>\= Show currently mounted file systems.</p>
</li>
<li><p><code>mount [device_path] [mount_point]</code>\= Mount a device.</p>
</li>
</ul>
<h3 id="heading-file-transfer"><strong>File Transfer</strong></h3>
<ul>
<li><p><code>scp [source_file] [user]@[remote_host]:[de stination_path]</code>\= Copy a file to a server directory securely.</p>
</li>
<li><p><code>wget [link]</code>\= Download files from FTP or web servers.</p>
</li>
<li><p><code>curl [link]</code>\= Transfer data to or from a server.</p>
</li>
</ul>
<h3 id="heading-file-compression"><strong>File Compression</strong></h3>
<ul>
<li><p><code>tar czf [archive.tar.gz]</code>\= Create a .gz compressed tar archive.</p>
</li>
<li><p><code>tar cf [archive.tar] [file/ directory]</code>\= Archive an existing file or directory</p>
</li>
<li><p><code>gzip [file_name]</code>, <code>gunzip [file_name.gz]</code>\= Compress or decompress .gz files.</p>
</li>
<li><p><code>unzip [archive.zip]</code>\= Extract a zip archive.</p>
</li>
</ul>
<h3 id="heading-packages"><strong>Packages</strong></h3>
<ol>
<li><strong>(Debian/Ubuntu)</strong></li>
</ol>
<ul>
<li><p><code>sudo apt update</code>\= Update package list.</p>
</li>
<li><p><code>sudo apt upgrade</code>\= Upgrade installed packages.</p>
</li>
<li><p><code>sudo apt install [package_name]</code>\= Install an APT package.</p>
</li>
<li><p><code>sudo apt remove [package_name]</code>\= Remove an APT package.</p>
</li>
</ul>
<ol start="2">
<li><strong>(RedHat/CentOS/Fedora)</strong></li>
</ol>
<ul>
<li><p><code>sudo yum update</code>\= Update package list and upgrade them.</p>
</li>
<li><p><code>sudo yum install [package_name]</code>\= Install a package</p>
</li>
<li><p><code>sudo yum remove [package_name]</code>\= Remove a package.</p>
</li>
</ul>
<h3 id="heading-searching"><strong>Searching</strong></h3>
<ul>
<li><p><code>find [path] -name [search_pattern]</code>\= Find files and directories.</p>
</li>
<li><p><code>grep [search_pattern] [file_name]</code>\= Search for a specific pattern in a file.</p>
</li>
<li><p><code>grep -r [search_pattern] [directory_name]</code>\= Recursively search for a pattern in a directory.</p>
</li>
<li><p><code>grep -i [search_pattern] [file_name]</code>\= Case insensitive search.</p>
</li>
<li><p><code>locate [name]</code>\= Locate all files and directories related to a particular name.</p>
</li>
<li><p><code>awk '[search_pattern] {print $0}' [file_name]</code>\= Print all lines matching a pattern in a file.</p>
</li>
<li><p><code>sed 's/[old_text]/ [new_text]/' [file_name]</code>\= Find and replace text in a specified file.</p>
</li>
<li><p><code>find [dir_name] -name [search_pattern]</code>\= Find files by name.</p>
</li>
</ul>
<h3 id="heading-service-management"><strong>Service Management</strong></h3>
<ul>
<li><p><code>systemctl start [service_name]</code>\= Start a service.</p>
</li>
<li><p><code>systemctl stop [service_name]</code>\= Stop a service.</p>
</li>
<li><p><code>systemctl restart [service_name]</code>\= Restart a service.</p>
</li>
<li><p><code>systemctl status [service_name]</code>\= Check service status.</p>
</li>
<li><p><code>systemctl enable [service_name]</code>\= Enable a service.</p>
</li>
<li><p><code>systemctl disable [service_name]</code>\= Disable a service.</p>
</li>
</ul>
<h3 id="heading-shell-scripting"><strong>Shell Scripting</strong></h3>
<ol>
<li><p><strong>Structure</strong></p>
<pre><code class="lang-basic"> #!/bin/bash
 echo <span class="hljs-string">"Hey! This is my Day14 of 90DaysOfDevOps"</span>
</code></pre>
</li>
<li><p><strong>Variables</strong></p>
<pre><code class="lang-basic">   #!/bin/bash
   <span class="hljs-keyword">NAME</span>=<span class="hljs-string">"Rakshita"</span>
   echo <span class="hljs-string">"Hey, $NAME"</span>
</code></pre>
</li>
<li><p><strong>Conditional Statements</strong></p>
<pre><code class="lang-basic">   <span class="hljs-keyword">if</span> [ condition ]; <span class="hljs-keyword">then</span>
     # Commands
   elif [ condition ]; <span class="hljs-keyword">then</span>
     # Commands
   <span class="hljs-keyword">else</span>
     # Commands
   fi
</code></pre>
</li>
<li><p><strong>Loops</strong></p>
<pre><code class="lang-basic">   <span class="hljs-keyword">for</span> i in {<span class="hljs-number">1..5</span>}; do
     echo <span class="hljs-string">"Iteration $i"</span>
   done

   <span class="hljs-keyword">while</span> [ condition ]; do
     # Commands
   done
</code></pre>
</li>
</ol>
<h3 id="heading-additional-useful-shell-commands"><strong>Additional useful shell commands</strong></h3>
<ul>
<li><p><code>man [command]</code>\= Display a built-in manual for a command.</p>
</li>
<li><p><code>history</code>\= Print the command history used in the terminal.</p>
</li>
<li><p><code>echo [text]</code>\= Display the text.</p>
</li>
<li><p><code>who</code>\= Show who is logged on.</p>
</li>
</ul>
<h3 id="heading-git-github-commands-cheat-sheet"><strong><mark>GIT-GITHUB COMMANDS CHEAT SHEET</mark></strong></h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>COMMAND NAME</strong></td><td><strong>USE</strong></td></tr>
</thead>
<tbody>
<tr>
<td>git init</td><td>initialize a local git repository</td></tr>
<tr>
<td>git add &lt;filename&gt;</td><td>move a particular file to staging area</td></tr>
<tr>
<td>git add .</td><td>move all the files to staging area</td></tr>
<tr>
<td>git commit -m "commit message"</td><td>creates a new commit in git with a commit message</td></tr>
<tr>
<td>git status</td><td>check the status of current repository and list the files you have changed</td></tr>
<tr>
<td>git log</td><td>show the list of all the commits made on a branch</td></tr>
<tr>
<td>git log --oneline</td><td>view commit ID briefly</td></tr>
<tr>
<td>git diff</td><td>show the changes you have made in a file</td></tr>
<tr>
<td>git diff HEAD</td><td>show difference between working directory and last commit</td></tr>
<tr>
<td>git config --global <a target="_blank" href="http://user.name">user.name</a> "name"</td><td>set global Git configuration for username</td></tr>
<tr>
<td>git config --global <a target="_blank" href="http://user.email">user.email</a> "email"</td><td>set global Git configuration for email address</td></tr>
<tr>
<td>git push origin &lt;branch name&gt;</td><td>push the branch to thr remote repository</td></tr>
<tr>
<td>git push -d origin &lt;branch_name&gt;</td><td>delete remote branch in git</td></tr>
<tr>
<td>git clone &lt;repository_URL&gt;</td><td>copy a git repository from remote source</td></tr>
<tr>
<td>git branch &lt;branch_name&gt;</td><td>creates a new branch</td></tr>
<tr>
<td>git checkout &lt;branch_name&gt;</td><td>switch from one branch to another</td></tr>
<tr>
<td>git checkout -b &lt;branch_name&gt;</td><td>creates and switch to a new branch</td></tr>
<tr>
<td>git branch -d &lt;branch_name&gt;</td><td>deletes the branch</td></tr>
<tr>
<td>git branch</td><td>show your current branch</td></tr>
<tr>
<td>git merge &lt;branch_name&gt;</td><td>merge one branch to another</td></tr>
<tr>
<td>git rebase</td><td>combines a sequence of commits to a new base commit and maintains a linear project history</td></tr>
<tr>
<td>git stash</td><td>stores something safely in hidden place</td></tr>
<tr>
<td>git stash list</td><td>show the stashed items list</td></tr>
<tr>
<td>git stash pop</td><td>bring back the file to staging area</td></tr>
<tr>
<td>git stash clear</td><td>clear the stashed items</td></tr>
<tr>
<td>git pull</td><td>copies changes from remote repository to local</td></tr>
<tr>
<td>git fetch</td><td>copies changes into local git repository</td></tr>
</tbody>
</table>
</div><div class="hn-table">
<table>
<thead>
<tr>
<td>git revert &lt;commit ID&gt;</td><td>revert commit changes</td></tr>
</thead>
<tbody>
<tr>
<td>git restore --stages &lt;filename&gt;</td><td>resetting a staged file</td></tr>
<tr>
<td>git rm &lt;filename&gt;</td><td>move the file to staging area</td></tr>
<tr>
<td>git mv &lt;old_filename&gt; &lt;new_filename&gt;</td><td>change the file name and move to staging area</td></tr>
<tr>
<td>git reset --soft &lt;commit_ID&gt;</td><td>move back all the items to staging area</td></tr>
<tr>
<td>git reset --hard &lt;commit_ID&gt;</td><td>discards all history and changes back to the specified commit</td></tr>
<tr>
<td>git remote -v</td><td>check if we have connected to any remote repository</td></tr>
<tr>
<td>.gitignore</td><td>a text file in a git repository that specifies which files and folders should be ignored and not tracked by version control</td></tr>
</tbody>
</table>
</div><p><strong>HAPPY LEARNING!😃</strong></p>
]]></content:encoded></item><item><title><![CDATA[Day 13 Task:  Advance Git & GitHub for DevOps Engineers]]></title><description><![CDATA[Git Branching
In Git, a branch is a new/separate version of a main repository. Git branch are pointer to a snapshot of your changes. The master branch is a default branch in Git./
When you want to add a new feature or fix a bug, no matter how big or ...]]></description><link>https://belwalrakshita08.hashnode.dev/day-13-task-advance-git-github-for-devops-engineers</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/day-13-task-advance-git-github-for-devops-engineers</guid><category><![CDATA[#90daysofdevops]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Git]]></category><category><![CDATA[#TWS]]></category><category><![CDATA[#shubhamLondhe]]></category><category><![CDATA[Devops]]></category><category><![CDATA[AWS]]></category><category><![CDATA[learning]]></category><category><![CDATA[Learning Journey]]></category><category><![CDATA[Hashnode]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Thu, 22 Aug 2024 09:13:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1724317658922/4013cd9b-fa0f-45cf-b94d-b8b8d41b05df.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-git-branching"><strong>Git Branching</strong></h3>
<p>In Git, a branch is a new/separate version of a main repository. Git branch are pointer to a snapshot of your changes. The master branch is a default branch in Git./</p>
<p>When you want to add a new feature or fix a bug, no matter how big or small it is, you create a new branch to make your changes. If the changes in new branch are well suited and tested, the new branch will be merged to master branch and applied in production.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724305195612/ced5118c-c886-4e9d-a3c1-d733c6e1f341.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-git-revert-and-reset"><strong>Git Revert and Reset</strong></h3>
<p><strong>Git Revert</strong> command helps you undo an existing commit. It does not delete any data in the process, rather it creates a new commit with the included files reverted to their previous state. So, your version control history moves forward while the state of your file moves backward.</p>
<p><strong>Git Reset</strong> is a powerful command that is used to undo local chnages to the state of a git repository. It is generally used at the time of merge conflicts to reset the conflicted files to their original state.</p>
<p>These forms correspond to command line arguments <code>--soft, --mixed, --hard</code>.</p>
<p><strong>--soft:</strong> Aims to change the HEAD (where the last commit is in your local machine) reference to a specific commit. For instance, if we realize that we forgot to add a file to the commit, we can move back using the --soft</p>
<p><strong>--mixed:</strong> Any changes that have been undone from the Staging Index are moved to the Working Directory.</p>
<p><strong>--hard:</strong> All the pending work in Staging area and Working Directory willbe lost.</p>
<h3 id="heading-git-rebase-and-merge"><strong>Git Rebase and Merge</strong></h3>
<p><strong>Git Rebase:</strong> Rebasing is the process of moving or combining a sequence of commits to a new base commit. Rebasing is most useful and easily visualised in the context of a feature branching workflow. The primary reason for rebasing is to maintain a linear project history.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724308411797/83909dca-c0fd-416f-8518-ccd4e0654141.png" alt class="image--center mx-auto" /></p>
<p><strong>Git Merge:</strong> It is used to combine the changes from one or more branches into the current branch. Git merge will associate a series of commits into one unified history. Generally, git merge is used to combine two branches.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724308760465/e6735a54-69ec-4676-a104-88a7f7ee42e2.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-tasks">Tasks</h2>
<h3 id="heading-task-1-feature-development-with-branches">Task 1: Feature Development with Branches</h3>
<ol>
<li><p><strong>Create a Branch and Add a Feature:</strong></p>
<ul>
<li><p>Add a text file called <code>version01.txt</code> inside the <code>Devops/Git/</code> directory with “This is the first feature of our application” written inside.</p>
<pre><code class="lang-basic">  <span class="hljs-keyword">mkdir</span> -p Devops/Git &amp;&amp; cd Devops/Git &amp;&amp; touch version01.txt
</code></pre>
<pre><code class="lang-basic">  vim version01.txt
</code></pre>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724309796674/5ee7768e-41e1-4c6d-8d7e-4e36e96475d1.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Create a new branch from <code>master</code>.</p>
<pre><code class="lang-basic">  git checkout -b dev
</code></pre>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724312032883/66c796b9-5c57-4610-98bb-06991a61143f.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p>Commit your changes with a message reflecting the added feature.</p>
<pre><code class="lang-basic"> git add Devops/Git/version01.txt
 git commit -m <span class="hljs-string">"Added new feature"</span>
</code></pre>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724312169900/53f9610a-78b5-472a-a99a-ddc5ea7ae762.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Push Changes to GitHub:</strong></p>
<ul>
<li><p>Push your local commits to the repository on GitHub.</p>
<pre><code class="lang-basic">  git push origin dev
</code></pre>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724312353649/63df6044-f5dd-4ffd-be0f-43dbd988c8f8.png" alt class="image--center mx-auto" /></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724312368933/8625f59a-6ca0-4bd3-ad5e-f11b3a4fe9fa.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p><strong>Add More Features with Separate Commits:</strong></p>
<p> Update <code>version01.txt</code> with the following lines, committing after each change:</p>
<ul>
<li><p>1st line: <code>This is the bug fix in development branch</code></p>
<pre><code class="lang-basic">  echo <span class="hljs-string">"This is the bug fix in development branch"</span> &gt;&gt; version01.txt
  git commit -am <span class="hljs-string">"Added feature2 in development branch"</span>
</code></pre>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724313270520/e308d612-3a6e-455e-9b75-a349bc4e52b9.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>2nd line: <code>This is gadbad code</code></p>
<pre><code class="lang-basic">  echo <span class="hljs-string">"This is gadbad code"</span> &gt;&gt; version01.txt
  git commit -am <span class="hljs-string">"Added feature3 in development branch"</span>
</code></pre>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724313446966/95fc69da-a8fb-49fb-87ba-3e8433c81518.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>3rd line: <code>This feature will gadbad everything from now</code></p>
<pre><code class="lang-basic">  echo <span class="hljs-string">"This feature will gadbad everything from now"</span> &gt;&gt; version01.txt
  git commit -am <span class="hljs-string">"Added feature4 in development branch"</span>
</code></pre>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724313551627/95922d7c-555e-4717-9713-e244d137ed35.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
</ol>
</li>
</ul>
</li>
</ol>
<ol start="4">
<li><p><strong>Restore the File to a Previous Version:</strong></p>
<ul>
<li><p>Revert or reset the file to where the content should be “This is the bug fix in development branch”.</p>
<pre><code class="lang-basic">  git revert HEAD~<span class="hljs-number">2</span>
</code></pre>
</li>
</ul>
</li>
</ol>
<h3 id="heading-task-2-working-with-branches">Task 2: Working with Branches</h3>
<ol>
<li><p><strong>Demonstrate Branches:</strong></p>
<ul>
<li><p>Create 2 or more branches and take screenshots to show the branch structure.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724316548486/1a7195ef-be6b-4eaa-a843-b4439b3789e0.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p><strong>Merge Changes into Master:</strong></p>
<ul>
<li><p>Make some changes to the <code>dev</code> branch and merge it into <code>master</code>.</p>
<pre><code class="lang-basic">  git checkout master
  git <span class="hljs-keyword">merge</span> dev
</code></pre>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724316845574/3433e269-d65b-456d-ac41-c7d944514df9.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p><strong>Practice Rebase:</strong></p>
<ul>
<li><p>Try rebasing and observe the differences.</p>
<pre><code class="lang-basic">  git rebase master
</code></pre>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724316891262/41625a71-9ed9-4b2b-8c21-5ceede5db276.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
</ol>
<p><strong>HAPPY LEARNING🌟</strong></p>
]]></content:encoded></item><item><title><![CDATA[Day 12 Task: Deep Dive in Git & GitHub for DevOps Engineers]]></title><description><![CDATA[What is Git and why is it important?
 Git is a Version Control System (VCS), which helps to keep track of the versions of a file. It is a free and open-source Version Control System used to handle small to very large projects efficiently. We can swit...]]></description><link>https://belwalrakshita08.hashnode.dev/day-12-task-deep-dive-in-git-github-for-devops-engineers</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/day-12-task-deep-dive-in-git-github-for-devops-engineers</guid><category><![CDATA[#90daysofdevops]]></category><category><![CDATA[Devops]]></category><category><![CDATA[#TWS]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Git]]></category><category><![CDATA[basics]]></category><category><![CDATA[AWS]]></category><category><![CDATA[learning]]></category><category><![CDATA[Hashnode]]></category><category><![CDATA[LinkedIn]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Wed, 21 Aug 2024 17:02:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1724259075739/b2c63534-5beb-482d-9ef5-65d1e834a292.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ol>
<li><h3 id="heading-what-is-git-and-why-is-it-important">What is Git and why is it important?</h3>
<p> Git is a Version Control System (VCS), which helps to keep track of the versions of a file. It is a free and open-source Version Control System used to handle small to very large projects efficiently. We can switch to any particular versions whenever and however we want.</p>
<p> Git is useful for Collaboration, Version Control, Code Conflicts etc.</p>
</li>
<li><h3 id="heading-what-is-the-difference-between-main-branch-and-master-branch">What is the difference between Main Branch and Master Branch?</h3>
<p> The default branch created locally in git is known as "master", while the default branch created in GitHub is known as "main".</p>
<p> Historically, the primary or the default branch for Git versions was named as "master".</p>
</li>
<li><h3 id="heading-explain-the-difference-between-git-and-github">Explain the difference between Git and GitHub?</h3>
<p> <strong>Git:-</strong> Git is Command-Line Interface tool (CLI). It is free, open-source and Distributed Version Control System (DVCS), that tracks the changes in any set of file.</p>
<p> <strong>GitHub:-</strong> GitHub is Graphical User Interface tool (GUI). GitHub is a web-based hosting service for git repositories. GitHub is more user-friendly, repositories are open here so that developers can contribute to one another's code.</p>
</li>
<li><h3 id="heading-how-do-you-create-a-new-repository-on-github">How do you create a new repository on GitHub?</h3>
<ul>
<li><p><strong>Login to your GitHub account:</strong> Go to login page of GitHub (<strong>GitHub.com</strong>) and enter your credentials to login your account.</p>
</li>
<li><p><strong>New Repository:</strong> Click on New to create a new repository.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724219800069/69debccb-7344-4d63-92ce-721fb3cc69c0.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Enter the details:</strong> Enter the repository name, Decription (optional), make it public or private, add README file (optional).</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724219823341/93a84300-f85a-4bab-a531-1546e54b3bed.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Create repository:</strong> Click on to Create Repository.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724219847901/3c0e752d-b6a8-4034-b73a-8320e5e3fcef.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Created:</strong> Your repository has created.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724220020507/3b2d622e-e09c-4018-b60d-bac7b5ceba95.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
</ol>
<ol start="5">
<li><h3 id="heading-what-is-the-difference-between-a-local-amp-remote-repository-how-to-connect-local-to-remote">What is the difference between a local &amp; remote repository? How to connect local to remote?</h3>
<p> <strong>Local repository:</strong> A local repository is a copy of the entire project’s history and codebase that resides on a developer’s machine. It allows developers to work offline, experiment with different ideas, and maintain a private workflow.</p>
<p> <strong>Remote Repository:</strong> A remote repository is a central shared repository hosted on a server, typically accessible over the internet. Examples are GitHub, GitLab, or Bitbucket.</p>
<p> <strong>Connect your local repository to remote repository</strong></p>
<ul>
<li><p><strong>Make a repository on GitHub (remote) as we made above</strong></p>
</li>
<li><p><strong>Initialize an empty git repository:</strong></p>
</li>
</ul>
</li>
</ol>
<pre><code class="lang-basic">    git init
</code></pre>
<ul>
<li><strong>Add remote repository URL:</strong></li>
</ul>
<pre><code class="lang-basic">     git <span class="hljs-comment">remote add origin &lt;remote_repo_URL&gt;</span>
</code></pre>
<ul>
<li><strong>Push to remote:</strong></li>
</ul>
<pre><code class="lang-basic">    git push origin main
</code></pre>
<h2 id="heading-tasks">Tasks</h2>
<ol>
<li><h3 id="heading-task-1">Task 1:</h3>
<ul>
<li><p>Set your user name and email address, which will be associated with your commits.</p>
<pre><code class="lang-basic">  # make directory
  <span class="hljs-keyword">mkdir</span> DevOps &amp;&amp; cd DevOps

  # initialize git repo
  git init

  # set username
  git config --global user.<span class="hljs-keyword">name</span> <span class="hljs-string">"rakshita"</span>

  #set email
  git config --global user.email <span class="hljs-string">"rakshitabelwal@gmail.com"</span>
</code></pre>
</li>
</ul>
</li>
</ol>
<h3 id="heading-task-2">Task 2:</h3>
<ul>
<li><p><strong>Create a repository named "DevOps" on GitHub.</strong></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724255077703/a3ddc228-bcf2-42ae-9ae3-d92d32497a1c.png" alt class="image--center mx-auto" /></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724255131418/9898409b-79d0-47fe-ac9d-43f49c177eca.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Connect your local repository to the repository on GitHub.</strong></p>
<p>  Connecting local repository to remote repository using Personal Access Token (PAT):</p>
<ul>
<li><strong>Create a PAT from your GitHub account-</strong></li>
</ul>
</li>
</ul>
<p>        Login to github -&gt; Go to Settings -&gt; Developer Settings -&gt; Personal Access Token -&gt; Token (Classic) -&gt; Generate New Token -&gt; Copy the token and save it somewhere</p>
<pre><code class="lang-basic">        git <span class="hljs-comment">remote add origin &lt;remote_repo_URL&gt;</span>
        git <span class="hljs-comment">remote -v</span>
</code></pre>
<p>        <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724257211456/363bdde5-6c11-4a3c-b707-08ef29ab4996.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-basic">        git <span class="hljs-comment">remote set-url origin https://&lt;PERSONAL_ACCESS_TOKEN&gt;@github.com/RakshitaBelwal/DevOps.git</span>
        git <span class="hljs-comment">remote -v</span>
</code></pre>
<ul>
<li><p>Create a new file in Devops/Git/Day-02.txt &amp; add some content to it.</p>
<pre><code class="lang-basic">  <span class="hljs-keyword">mkdir</span> -p DevOps/Git &amp;&amp; cd DevOps/Git
  touch Day-<span class="hljs-number">02.</span>txt
</code></pre>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724257946620/0ccbcdd5-b0c1-4a3a-bc78-dee490459fc7.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Push your local commits to the repository on GitHub.</p>
<pre><code class="lang-basic">  git add Day-<span class="hljs-number">02.</span>txt
  git commit -m <span class="hljs-string">"My first commit"</span>
  git push origin master
</code></pre>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724258777293/fd054b3c-dbc2-43b4-86fc-5909d645229f.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<h3 id="heading-conclusion">Conclusion</h3>
<p>    Mastering the basics of Git and GitHub is essential for anyone involved in software development or version control. With these tools, developers can streamline their workflows, ensure code integrity, and collaborate more effectively, making Git and GitHub foundational skills in modern development practices.</p>
<p><strong>HAPPY LEARNING🚀</strong></p>
]]></content:encoded></item><item><title><![CDATA[Day 11 : Error Handling in Shell Scripting]]></title><description><![CDATA[Tasks:
Task 1: Checking Exit Status

Write a script that attempts to create a directory and checks if the command was successful. If not, print an error message.

Create a file:
 vim create_dir.sh


Enter the script in file:
 #!/bin/bash

 # Create d...]]></description><link>https://belwalrakshita08.hashnode.dev/day-11-error-handling-in-shell-scripting</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/day-11-error-handling-in-shell-scripting</guid><category><![CDATA[#90daysofdevops]]></category><category><![CDATA[Devops]]></category><category><![CDATA[shell script]]></category><category><![CDATA[#TWS]]></category><category><![CDATA[Bash]]></category><category><![CDATA[learning]]></category><category><![CDATA[bash script]]></category><category><![CDATA[Linux]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Fri, 16 Aug 2024 07:24:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1723792538144/3ae8f514-1e3e-42f3-97c2-bf1f62817f33.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-tasks"><strong>Tasks:</strong></h3>
<h3 id="heading-task-1-checking-exit-status">Task 1: Checking Exit Status</h3>
<ul>
<li><p>Write a script that attempts to create a directory and checks if the command was successful. If not, print an error message.</p>
<ol>
<li><p>Create a file:</p>
<pre><code class="lang-basic"> vim create_dir.sh
</code></pre>
</li>
<li><p>Enter the script in file:</p>
<pre><code class="lang-basic"> #!/bin/bash

 # Create directory
 <span class="hljs-keyword">mkdir</span> /home/ubuntu/day11

 # Check exit status
 <span class="hljs-keyword">if</span> [ $? -ne <span class="hljs-number">0</span> ]; <span class="hljs-keyword">then</span>
         echo <span class="hljs-string">"Directory was not created"</span>
         exit <span class="hljs-number">1</span>
 fi
         echo <span class="hljs-string">"Directory created successfully"</span>
</code></pre>
</li>
<li><p>Make it executable and execute. The OUTPUT will be:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723786791786/dcafc65e-70c3-4ccb-a699-1aeba4bf3993.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
</li>
</ul>
<h3 id="heading-task-2-using-if-statements-for-error-checking">Task 2: Using <code>if</code> Statements for Error Checking</h3>
<p>Modify the script from Task 1 to include more commands (e.g., creating a file inside the directory) and use <code>if</code> statements to handle errors at each step.</p>
<pre><code class="lang-basic">#!/bin/bash

# Create directory inside directory
<span class="hljs-keyword">mkdir</span> /home/ubuntu/day11/task2_dir
<span class="hljs-keyword">if</span> [ $? -ne <span class="hljs-number">0</span> ]; <span class="hljs-keyword">then</span>
        echo <span class="hljs-string">"Failed to create Directory /home/ubuntu/day11/task2_dir "</span>
        exit <span class="hljs-number">1</span>
fi

# Create file inside directory
touch /home/ubuntu/day11/task2_dir/newfile.txt
<span class="hljs-keyword">if</span> [ $? -ne <span class="hljs-number">0</span> ]; <span class="hljs-keyword">then</span>
        echo <span class="hljs-string">"Failed to create file /home/ubuntu/day11/task2_dir/newfile.txt"</span>
        exit <span class="hljs-number">1</span>
fi
        echo <span class="hljs-string">"Directory and file created successfully /home/ubuntu/day11/task2_dir/newfile.txt"</span>
</code></pre>
<p>OUTPUT:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723789067964/2ca39afa-7a82-4c8c-9a1a-71ddb8cae7f4.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-task-3-using-trap-for-cleanup">Task 3: Using <code>trap</code> for Cleanup</h3>
<ul>
<li><p>Write a script that creates a temporary file and sets a <code>trap</code> to delete the file if the script exits unexpectedly.</p>
<pre><code class="lang-basic">  #!/bin/bash

  # Create a temporary file
  tempfile=<span class="hljs-string">"temp_file.txt"</span>
  touch $tempfile

  # Trap <span class="hljs-keyword">to</span> <span class="hljs-keyword">delete</span> temporary file
  trap <span class="hljs-string">"rm -f $tempfile; echo 'Temporary file deleted'"</span> EXIT

  # Stimualte with sleep (<span class="hljs-number">10</span> seconds)
  echo <span class="hljs-string">"Script running..."</span>
  sleep <span class="hljs-number">10</span>

  echo <span class="hljs-string">"Script completed successfully"</span>
</code></pre>
<p>  OUTPUT: The script ran for 10 seconds and then temporary file deleted.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723790454576/86b236a2-b54a-421b-a63d-5a2ea76e53b9.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<h3 id="heading-task-4-redirecting-errors">Task 4: Redirecting Errors</h3>
<ul>
<li><p>Write a script that tries to read a non-existent file and redirects the error message to a file called <code>error.log</code>.</p>
<pre><code class="lang-basic">  #!/bin/bash

  # <span class="hljs-keyword">Read</span> non-existing file <span class="hljs-keyword">and</span> redirect <span class="hljs-keyword">error</span>
  cat non_existing_file <span class="hljs-number">2</span>&gt; <span class="hljs-keyword">error</span>.<span class="hljs-keyword">log</span>
</code></pre>
<p>  OUTPUT:</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723791350991/d93e48b7-787f-4984-8c9e-ca5fcca50052.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<h3 id="heading-task-5-creating-custom-error-messages">Task 5: Creating Custom Error Messages</h3>
<ul>
<li><p>Modify one of the previous scripts to include custom error messages that provide more context about what went wrong.</p>
<pre><code class="lang-basic">  #!/bin/bash

  # Create directory
  <span class="hljs-keyword">mkdir</span> /home/ubuntu/task5_dir

  <span class="hljs-keyword">if</span> [ $? -eq <span class="hljs-number">0</span> ]; <span class="hljs-keyword">then</span>
          echo <span class="hljs-string">"Directory created successfully"</span>
  <span class="hljs-keyword">else</span>
          echo <span class="hljs-string">"Failed: Directory was not created for /home/ubuntu/task5_dir. Check if you have required permissions!"</span>
  fi

  # Create a file inside directory
  touch /home/ubuntu/task5_dir/myfile5.txt

  <span class="hljs-keyword">if</span> [ $? -eq <span class="hljs-number">0</span> ]; <span class="hljs-keyword">then</span>
          echo <span class="hljs-string">"File created successfully"</span>
  <span class="hljs-keyword">else</span>
          echo <span class="hljs-string">"Failed: File was not created for /home/ubuntu/task5_dir/myfile5.txt. Check, your directory already exist and the file has its required permissions! "</span>
  fi
</code></pre>
<p>  OUTPUT: When the task successfully completed.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723792301607/7b34ba28-eccc-434b-8f92-ec39918c3fb5.png" alt class="image--center mx-auto" /></p>
<p>  OUTPUT: When the task failed to complete.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723792467348/bcfed41f-6399-4a44-8a50-f211513a9d7b.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<p><strong>HAPPY SCRIPTING</strong>🌟</p>
]]></content:encoded></item><item><title><![CDATA[Day 10 Task: Log Analyzer and Report Generator]]></title><description><![CDATA[Challenge Title: Log Analyzer and Report Generator
Scenario
You are a system administrator responsible for managing a network of servers. Every day, a log file is generated on each server containing important system events and error messages. As part...]]></description><link>https://belwalrakshita08.hashnode.dev/day-10-task-log-analyzer-and-report-generator</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/day-10-task-log-analyzer-and-report-generator</guid><category><![CDATA[#90daysofdevops]]></category><category><![CDATA[shell scripting]]></category><category><![CDATA[LogAnalysis]]></category><category><![CDATA[report]]></category><category><![CDATA[Bash]]></category><category><![CDATA[Devops]]></category><category><![CDATA[AWS]]></category><category><![CDATA[learning]]></category><category><![CDATA[Hashnode]]></category><category><![CDATA[Linux]]></category><category><![CDATA[#TWS]]></category><category><![CDATA[#shubhamLondhe]]></category><category><![CDATA[LinkedIn]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Thu, 15 Aug 2024 16:38:05 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1723739740711/78d1330c-7cfa-458c-9e4f-46b4f639170f.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-challenge-title-log-analyzer-and-report-generator">Challenge Title: Log Analyzer and Report Generator</h3>
<h3 id="heading-scenario">Scenario</h3>
<p>You are a system administrator responsible for managing a network of servers. Every day, a log file is generated on each server containing important system events and error messages. As part of your daily tasks, you need to analyze these log files, identify specific events, and generate a summary report.</p>
<h2 id="heading-task">Task</h2>
<p>Write a Bash script that automates the process of analyzing log files and generating a daily summary report. The script should perform the following steps:</p>
<ol>
<li><p><strong>Input:</strong> The script should take the path to the log file as a command-line argument.</p>
</li>
<li><p><strong>Error Count:</strong> Analyze the log file and count the number of error messages. An error message can be identified by a specific keyword (e.g., "ERROR" or "Failed"). Print the total error count.</p>
</li>
<li><p><strong>Critical Events:</strong> Search for lines containing the keyword "CRITICAL" and print those lines along with the line number.</p>
</li>
<li><p><strong>Top Error Messages:</strong> Identify the top 5 most common error messages and display them along with their occurrence count.</p>
</li>
<li><p><strong>Summary Report:</strong> Generate a summary report in a separate text file. The report should include:</p>
<ul>
<li><p>Date of analysis</p>
</li>
<li><p>Log file name</p>
</li>
<li><p>Total lines processed</p>
</li>
<li><p>Total error count</p>
</li>
<li><p>Top 5 error messages with their occurrence count</p>
</li>
<li><p>List of critical events with line numbers</p>
</li>
</ul>
</li>
<li><p><strong>Optional Enhancement:</strong> Add a feature to automatically archive or move processed log files to a designated directory after analysis.</p>
</li>
</ol>
<h2 id="heading-tips">Tips</h2>
<ul>
<li><p>Use <code>grep</code>, <code>awk</code>, and other command-line tools to process the log file.</p>
</li>
<li><p>Utilize arrays or associative arrays to keep track of error messages and their counts.</p>
</li>
<li><p>Use appropriate error handling to handle cases where the log file doesn't exist or other issues arise.</p>
</li>
</ul>
<h3 id="heading-solution">Solution:</h3>
<ol>
<li><p>Create a folder and then a log file inside:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723739117361/8d31682a-9dab-4fb5-ac76-cf63ded2795d.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>In log_analyzer.sh insert the shell script:</p>
<pre><code class="lang-basic"> #!/bin/bash

 <span class="hljs-keyword">if</span> [ $# -ne <span class="hljs-number">1</span> ]; <span class="hljs-keyword">then</span>
         echo <span class="hljs-string">"Usage: $0 /home/ubuntu/logs/log_file.log"</span>
         exit <span class="hljs-number">1</span>
 fi

 log_file=$<span class="hljs-number">1</span>
 summary_report=<span class="hljs-string">"summary_$(date +%Y-%m-%d).txt"</span>

 # check <span class="hljs-keyword">if</span> the <span class="hljs-keyword">log</span> file exists
 <span class="hljs-keyword">if</span> [ ! -f <span class="hljs-string">"$log_file"</span> ]; <span class="hljs-keyword">then</span>
   echo <span class="hljs-string">"Error: Log file not found!"</span>
   exit <span class="hljs-number">1</span>
 fi

 # Count the total number of lines in the <span class="hljs-keyword">log</span> file
 total_lines=$(wc -l &lt; <span class="hljs-string">"$log_file"</span>)

 # Count the number of <span class="hljs-keyword">error</span> messages
 error_count=$(grep -c <span class="hljs-string">"ERROR"</span> <span class="hljs-string">"$log_file"</span>)

 # Search <span class="hljs-keyword">for</span> critical events
 critical_events=$(grep -n <span class="hljs-string">"CRITICAL"</span> <span class="hljs-string">"$log_file"</span>)

 # Identify the top <span class="hljs-number">5</span> most <span class="hljs-keyword">common</span> <span class="hljs-keyword">error</span> messages
 declare -A error_messages
 <span class="hljs-keyword">while</span> IFS= <span class="hljs-keyword">read</span> -r <span class="hljs-keyword">line</span>; do
      <span class="hljs-keyword">if</span> [[ <span class="hljs-string">"$line"</span> == <span class="hljs-string">"ERROR"</span> ]]; <span class="hljs-keyword">then</span>
            ((error_messages[<span class="hljs-string">"$message"</span>]++))
      fi
 done &lt; <span class="hljs-string">"$log_file"</span>

 TOP_ERRORS=$(<span class="hljs-keyword">for</span> msg in <span class="hljs-string">"${!ERROR_MESSAGES[@]}"</span>; do
   echo <span class="hljs-string">"${ERROR_MESSAGES[$msg]}: $msg"</span>
 done | sort -nr | head -<span class="hljs-number">5</span>)

 # Generate summary report
 {

 echo <span class="hljs-string">"Date of analysis: $(date)"</span>
 echo <span class="hljs-string">"Log file: $log_file"</span>
 echo <span class="hljs-string">"Total line processed: $total_lines"</span>
 echo <span class="hljs-string">"Total error count: $error_count"</span>
 echo <span class="hljs-string">"Top 5 error messages:"</span>
 echo <span class="hljs-string">"$TOP_ERRORS"</span>
 echo <span class="hljs-string">"Critical events:"</span>
 echo <span class="hljs-string">"$critical_events"</span>

 } &gt; <span class="hljs-string">"$summary_report"</span>

 # <span class="hljs-keyword">Print</span> the summary report <span class="hljs-keyword">to</span> the console
 cat <span class="hljs-string">"$summary_report"</span>

 # Optional: Archive <span class="hljs-keyword">or</span> move the processed <span class="hljs-keyword">log</span> file
 archive_dir=<span class="hljs-string">"processed_logs"</span>
 <span class="hljs-keyword">mkdir</span> -p <span class="hljs-string">"$archive_dir"</span>
 mv <span class="hljs-string">"$summary_report"</span> <span class="hljs-string">"$archive_dir/"</span>

 echo <span class="hljs-string">"Log file generated and saved to $summary_report"</span>
</code></pre>
</li>
<li><p>Change the file permission to make it executable and execute:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723739434393/741af544-51a0-479a-bc8d-0fe2085541a8.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Check summary report:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723739614587/d6ee9bac-e8b0-4469-b5e3-86982cd1db67.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
<p><strong>HAPPY SCRIPTING!🚀</strong></p>
]]></content:encoded></item><item><title><![CDATA[Day 9 Task: Shell Scripting Challenge Directory Backup with Rotation]]></title><description><![CDATA[TASK:
Create a bash script that takes a directory path as a command-line argument and performs a backup of the directory. The script should create timestamped backup folders and copy all the files from the specified directory into the backup folder.
...]]></description><link>https://belwalrakshita08.hashnode.dev/day-9-task-shell-scripting-challenge-directory-backup-with-rotation</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/day-9-task-shell-scripting-challenge-directory-backup-with-rotation</guid><category><![CDATA[backupwithrotation]]></category><category><![CDATA[#90daysofdevops]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Bash]]></category><category><![CDATA[shell]]></category><category><![CDATA[shell script]]></category><category><![CDATA[Hashnode]]></category><category><![CDATA[learning]]></category><category><![CDATA[#TWS]]></category><category><![CDATA[#shubhamLondhe]]></category><category><![CDATA[Linux]]></category><category><![CDATA[LinkedIn]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Fri, 09 Aug 2024 18:26:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1723227874909/dfdd5bb3-5b2a-48ae-9ca1-c8152d9532f8.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-task"><strong>TASK:</strong></h3>
<p><strong>Create a bash script that takes a directory path as a command-line argument and performs a backup of the directory. The script should create timestamped backup folders and copy all the files from the specified directory into the backup folder.</strong></p>
<p><strong>Additionally, the script should implement a rotation mechanism to keep only the last 3 backups. This means that if there are more than 3 backup folders, the oldest backup folders should be removed to ensure only the most recent backups are retained.</strong></p>
<ol>
<li><p>Create two directories- One is to write the shell script (<strong>scripts</strong>), another is to take the backup (<strong>backups</strong>):</p>
<pre><code class="lang-basic"> <span class="hljs-keyword">mkdir</span> scripts backups
</code></pre>
</li>
<li><p>Enter into the scripts directory and make a file named <strong>backup_with_rotation.sh:</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723226084888/e4ef5660-5d1c-408f-8fc7-3dd47fca7288.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Insert the script:</p>
<pre><code class="lang-basic"> #!/bin/bash

 &lt;&lt; readme
 This is a script <span class="hljs-keyword">to</span> take a backup of directory
 usage:
 ./backup_with_rotation.sh &lt;path of directory&gt; &lt;path of backup directory&gt;

 readme

 source_dir=$<span class="hljs-number">1</span>
 backup_dir=$<span class="hljs-number">2</span>
 timestamp=$(date <span class="hljs-comment">'+%Y-%m-%d-%H-%M-%S')</span>

 function create_backup {
 zip -r <span class="hljs-string">"${backup_dir}/backup_${timestamp}.zip"</span> <span class="hljs-string">"${source_dir}"</span> &gt; /dev/null

 <span class="hljs-keyword">if</span> [ $? -eq <span class="hljs-number">0</span> ]; <span class="hljs-keyword">then</span>

         echo <span class="hljs-string">"Backup created successfully"</span>
 <span class="hljs-keyword">else</span>
         echo <span class="hljs-string">"Backup was not performed for $timestamp"</span>
 fi
 }

 function perform_rotation {
             backups=($(ls -t <span class="hljs-string">"$backup_dir/backup_"</span>*.zip))

             <span class="hljs-keyword">if</span> [ <span class="hljs-string">"${#backups[@]}"</span> -gt <span class="hljs-number">3</span> ]; <span class="hljs-keyword">then</span>
                     backups_to_<span class="hljs-comment">remove=("${backups[@]:3}")</span>
                     <span class="hljs-keyword">for</span> backup in <span class="hljs-string">"${backups_to_remove[@]}"</span>;
                     do
                             rm <span class="hljs-string">"$backup"</span>
                     done
             fi
 }

 create_backup
 perform_rotation
</code></pre>
</li>
<li><p>Change the permissions of this file to make it executable:</p>
<pre><code class="lang-basic"> chmod <span class="hljs-number">700</span> backup_with_rotation.sh
</code></pre>
</li>
<li><p>Install zip:</p>
<pre><code class="lang-basic">    sudo apt install zip
</code></pre>
</li>
<li><p>Execute:</p>
<pre><code class="lang-basic"> ./backup_with_rotation.sh /home/ubuntu/scripts /home/ubuntu/backups
</code></pre>
<p> Here,</p>
<p> /home/ubuntu/scripts = path of directory</p>
<p> /home/ubuntu/backups = path of backup directory</p>
</li>
<li><p>Take backup 4-5 times:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723227114509/358e7f37-b3b4-463f-a9fc-b69502236395.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Check if the last 3 backups are there in your backups directory:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1723227181662/32845d9b-4256-447e-b4f6-21d6a626afc3.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<p>In this guide, we've walked through the creation of a robust bash script that automates the backup of directories with ease. By taking a directory path as a command-line argument, this script efficiently creates timestamped backup folders, ensuring that each backup is neatly organized and easily identifiable.</p>
<p>Moreover, we've implemented a rotation mechanism to keep only the last three backups, effectively managing storage space while maintaining the most recent data. This approach not only simplifies the backup process but also ensures that your system remains clutter-free.</p>
<p>Remember, automation is key to efficiency, and this backup script is a small yet powerful step in that direction.</p>
<p>Happy scripting!</p>
]]></content:encoded></item><item><title><![CDATA[Day 8 Task:  Shell Scripting Challenge]]></title><description><![CDATA[Task 1: Comments
In bash scripts, comments are used to add explanatory notes or disable certain lines of code. Your task is to create a bash script with comments explaining what the script does.
Make a file named task1.sh and insert the script:
  #!/...]]></description><link>https://belwalrakshita08.hashnode.dev/day-8-task-shell-scripting-challenge</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/day-8-task-shell-scripting-challenge</guid><category><![CDATA[#90daysofdevops]]></category><category><![CDATA[Devops]]></category><category><![CDATA[shell]]></category><category><![CDATA[shell scripting]]></category><category><![CDATA[#TWS]]></category><category><![CDATA[learning]]></category><category><![CDATA[AWS]]></category><category><![CDATA[Hashnode]]></category><category><![CDATA[Linux]]></category><category><![CDATA[LinkedIn]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Tue, 30 Jul 2024 15:57:05 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1722354741410/d3089668-95d6-4f0b-b0e0-f2b07bc19be7.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-task-1-comments">Task 1: Comments</h3>
<p><strong>In bash scripts, comments are used to add explanatory notes or disable certain lines of code. Your task is to create a bash script with comments explaining what the script does.</strong></p>
<p>Make a file named task1.sh and insert the script:</p>
<pre><code class="lang-basic">  #!/bin/bash

  # This script prints about what comment does

  echo <span class="hljs-string">"The comment (#) are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters"</span>
</code></pre>
<p>Make this file executable:</p>
<pre><code class="lang-basic">chmod <span class="hljs-number">700</span> task1.sh
</code></pre>
<p>Execute the script:</p>
<pre><code class="lang-basic">./task1.sh
</code></pre>
<h3 id="heading-task-2-echo">Task 2: Echo</h3>
<p><strong>The echo command is used to display messages on the terminal. Your task is to create a bash script that uses echo to print a message of your choice.</strong></p>
<pre><code class="lang-basic">#!/bin/bash

echo <span class="hljs-string">"Hello, this is my Day 8 of 90DaysOfDevOPs challenge"</span>
</code></pre>
<p>Run the script.</p>
<h3 id="heading-task-3-variables">Task 3: Variables</h3>
<p><strong>Variables in bash are used to store data and can be referenced by their name. Your task is to create a bash script that declares variables and assigns values to them.</strong></p>
<pre><code class="lang-basic">#!/bin/bash

<span class="hljs-keyword">name</span>=<span class="hljs-string">"Rakshita"</span>
challenge=<span class="hljs-string">"90DaysOfDevOps challenge"</span>

echo <span class="hljs-string">"Hello, my name is $name and this is my day 8 of $challenge"</span>
</code></pre>
<p>Run the script.</p>
<h3 id="heading-task-4-using-variables">Task 4: Using Variables</h3>
<p><strong>Now that you have declared variables, let's use them to perform a simple task. Create a bash script that takes two variables (numbers) as input and prints their sum using those variables.</strong></p>
<pre><code class="lang-basic">#!/bin/bash

num1=<span class="hljs-number">6</span>
num2=<span class="hljs-number">9</span>
sum=$((num1 + num2))

echo <span class="hljs-string">"The sum of $num1 and $num2 is $sum"</span>
</code></pre>
<p>Run the script.</p>
<h3 id="heading-task-5-using-built-in-variables">Task 5: Using Built-in Variables</h3>
<p><strong>Bash provides several built-in variables that hold useful information. Your task is to create a bash script that utilizes at least three different built-in variables to display relevant information.</strong></p>
<pre><code class="lang-basic">#!/bin/bash

echo <span class="hljs-string">"Current user: $USER"</span>

echo <span class="hljs-string">"Home directory: $HOME"</span>

echo <span class="hljs-string">"Current working directory: $PWD"</span>
</code></pre>
<h3 id="heading-task-6-wildcards">Task 6: Wildcards</h3>
<p><strong>Wildcards are special characters used to perform pattern matching when working with files. Your task is to create a bash script that utilizes wildcards to list all the files with a specific extension in a directory.</strong></p>
<p>Make few .txt files in current directory:</p>
<pre><code class="lang-basic">touch file1.txt file2.txt
</code></pre>
<p>Create another new file:</p>
<pre><code class="lang-basic">vim task6.sh
</code></pre>
<p>Enter the script:</p>
<pre><code class="lang-basic">#!/bin/bash

echo <span class="hljs-string">"Listing all .txt files in current directory"</span>
ls *.txt
</code></pre>
<p>Make this file executable:</p>
<pre><code class="lang-basic">chmod <span class="hljs-number">700</span> task6.sh
</code></pre>
<p>Run the script:</p>
<pre><code class="lang-basic">./task6.sh
</code></pre>
<h3 id="heading-conclusion">Conclusion</h3>
<p>In this series of tasks, we explored some fundamentals of bash scripting including comments, echo, commands,variables, build-in-variables and wildcards. This foundation euips us with the skills to write more complex and functional bash scripts, facilitating efficient and automated tasks in a Unix-like environment.</p>
<p>Happy learning!🚀</p>
]]></content:encoded></item><item><title><![CDATA[Day 7: Understanding Package Manager and Systemctl]]></title><description><![CDATA[What is a Package Manager in Linux?
In simpler words, a package manager is a tool that allows users to install, remove, upgrade, configure and manage software packages on an operating system. The package manager can be a graphical application like a ...]]></description><link>https://belwalrakshita08.hashnode.dev/day-7-understanding-package-manager-and-systemctl</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/day-7-understanding-package-manager-and-systemctl</guid><category><![CDATA[#90daysofdevops]]></category><category><![CDATA[Devops]]></category><category><![CDATA[#TWS]]></category><category><![CDATA[learning]]></category><category><![CDATA[Hashnode]]></category><category><![CDATA[package manager]]></category><category><![CDATA[Linux]]></category><category><![CDATA[systemd]]></category><category><![CDATA[systemctl]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Wed, 24 Jul 2024 06:57:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721804057274/c925f114-3cd7-44c9-8a19-2486f556d34f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-what-is-a-package-manager-in-linux">What is a Package Manager in Linux?</h3>
<p>In simpler words, a package manager is a tool that allows users to install, remove, upgrade, configure and manage software packages on an operating system. The package manager can be a graphical application like a software center or a command line tool like <strong>apt-get</strong> or <strong>pacman</strong>.</p>
<h3 id="heading-what-is-package">What is Package?</h3>
<p>A package contains all the necessary data required for the installation and maintenance of the software package. These packages are created by someone known as a package maintainer. A package maintainer takes care of the packages. They ensure active maintenance, bug fixes if any, and the final compilation of the package.</p>
<h3 id="heading-different-kinds-of-package-managers">Different Kinds of Package Managers</h3>
<p>There are different package managers for different <strong>Linux distributions</strong>. Here I have shown some of the popular package managers:</p>
<ol>
<li><h4 id="heading-advanced-packaging-tool-apt"><strong>Advanced Packaging Tool (APT)</strong></h4>
<p> The <strong>APT package manager</strong> is used in the Debian-based Linux distribution and its derivatives. APT package manager handles the <strong>.deb</strong> format packages. It install, remove, upgrade packages, and resolve dependencies automatically. It uses the <strong>apt, apt-get</strong> command line.</p>
</li>
<li><h4 id="heading-yellow-dog-updater-modified-yum"><strong>Yellow-Dog Updater Modified (YUM)</strong></h4>
<p> <strong>YUM package manager</strong> is used in the RedHat-based Linux distribution and its derivatives. It is the default common package manager in RedHat and handles the <strong>.rpm</strong> formatted packages. Yum checks the dependencies with header files and package metadata and resolves dependencies while installing or updating packages.</p>
</li>
<li><h4 id="heading-dandified-yum-dnf"><strong>Dandified YUM (DNF)</strong></h4>
<p> <strong>DNF package manager</strong> is the successor and the top of the <strong>yum</strong> package manager. It is is also used in Red Hat-based distribution. Dnf also uses the <strong>.rpm</strong> file extension. Dnf provides faster performance, Parallel downloading, a rich command line interface, and enhanced dependency resolution by using a dependency solver.</p>
</li>
<li><h4 id="heading-pacman"><strong>Pacman</strong></h4>
<p> <strong>Pacman</strong> is a utility that is used in <strong>Arch Linux distribution</strong> for managing software packages. Using simple compressed files, it maintains a text-based database. The file extension for the Pacman package manager is  <strong>.pkg.tar.xz.</strong> Pacman is lightweight, fast, and high-speed packaging, it provides two types of repositories and automatically upgrades the package.</p>
</li>
</ol>
<h3 id="heading-tasks">TASKS</h3>
<p>How to install Docker and Jenkins using package managers on Ubuntu and CentOS.</p>
<p><strong>DOCKER INSTALLATION ON UBUNTU</strong></p>
<ol>
<li><p>Update Packages:</p>
<pre><code class="lang-basic"> sudo apt-<span class="hljs-keyword">get</span> update
</code></pre>
</li>
<li><p>Install Docker:</p>
<pre><code class="lang-basic"> sudo apt install docker.io -y
</code></pre>
</li>
<li><p>Verify the installation:</p>
<pre><code class="lang-basic"> docker --version
</code></pre>
<p> <strong>ON CENTOS</strong></p>
</li>
<li><p>Set up the repository:</p>
<pre><code class="lang-basic"> sudo yum install -y yum-utils
 sudo yum-config-manager --add-repo https://download.docker.<span class="hljs-keyword">com</span>/linux/centos/docker-ce.repo
</code></pre>
</li>
<li><p>Install Docker Engine, containerd, and Docker Compose:</p>
<pre><code class="lang-basic"> sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
</code></pre>
</li>
<li><p>Verify the installation:</p>
<pre><code class="lang-basic"> docker --version
</code></pre>
</li>
</ol>
<p><strong>JENKINS INSTALLATION ON UBUNTU</strong></p>
<ol>
<li><p>Update package list:</p>
<pre><code class="lang-basic"> sudo apt-<span class="hljs-keyword">get</span> update
</code></pre>
</li>
<li><p>Install Java (Jenkins requires Java):</p>
<pre><code class="lang-basic"> sudo apt-<span class="hljs-keyword">get</span> install openjdk-<span class="hljs-number">11</span>-jdk -y
</code></pre>
</li>
<li><p>Add the Jenkins repository key:</p>
<pre><code class="lang-basic"> curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.<span class="hljs-keyword">key</span> | sudo tee /<span class="hljs-keyword">usr</span>/share/keyrings/jenkins-keyring.<span class="hljs-keyword">asc</span> &gt; /dev/null
</code></pre>
</li>
<li><p>Add the Jenkins repository:</p>
<pre><code class="lang-basic"> echo deb [signed-by=/<span class="hljs-keyword">usr</span>/share/keyrings/jenkins-keyring.<span class="hljs-keyword">asc</span>] https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.<span class="hljs-keyword">list</span>.d/jenkins.<span class="hljs-keyword">list</span> &gt; /dev/null
</code></pre>
</li>
<li><p>Update the package list again:</p>
<pre><code class="lang-basic"> sudo apt-<span class="hljs-keyword">get</span> update
</code></pre>
</li>
<li><p>Install Jenkins:</p>
<pre><code class="lang-basic"> sudo apt-<span class="hljs-keyword">get</span> install jenkins -y
</code></pre>
</li>
<li><p>Check the status:</p>
<pre><code class="lang-basic"> sudo systemctl status jenkins
</code></pre>
</li>
</ol>
<p><strong>ON CENTOS 9</strong></p>
<ol>
<li><p>Install java:</p>
<pre><code class="lang-basic"> sudo dnf install java-<span class="hljs-number">11</span>-openjdk-devel -y
</code></pre>
</li>
<li><p>Install wget:</p>
<pre><code class="lang-basic"> sudo yum install wget
</code></pre>
</li>
<li><p>Install Jenkins:</p>
<pre><code class="lang-basic"> sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

 sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.<span class="hljs-keyword">key</span>

 sudo dnf upgrade

 sudo dnf install jenkins
</code></pre>
</li>
<li><p>Start Jenkins:</p>
<pre><code class="lang-basic"> sudo systemctl start jenkins
</code></pre>
</li>
<li><p>Check Status:</p>
<pre><code class="lang-basic"> sudo systemctl status jenkins
</code></pre>
</li>
</ol>
<h3 id="heading-systemctl-and-systemd">Systemctl and Systemd</h3>
<p><strong>systemd</strong> gives us the <strong>systemctl</strong> commands suite which is mostly used to enable services to start at boot time. We can also start, stop, reload, restart and check status of services with the help of <strong>systemctl</strong> .</p>
<p>We can do, for example, <strong>sudo systemctl enable service_name</strong>, and <strong>service_name</strong> will automatically start at boot time. We can also disable services not to start at boot time.</p>
<h3 id="heading-tasks-1">Tasks</h3>
<ol>
<li><p><strong><em>Check Docker Service Status:</em></strong></p>
<ul>
<li>Check the status of the Docker service on your system (ensure you have completed the installation tasks above).</li>
</ul>
</li>
</ol>
<pre><code class="lang-basic">    sudo systemctl status docker
</code></pre>
<ol start="2">
<li><p><strong><em>Manage Jenkins Service:</em></strong></p>
<ul>
<li>Stop the Jenkins service and post before and after screenshots.</li>
</ul>
</li>
</ol>
<p>    <strong>Before stopping the jenkins service:</strong></p>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721797990797/092cd61e-b200-439d-89a0-f8250b5f22c1.png" alt class="image--center mx-auto" /></p>
<p>    <strong>After stopping the jenkins service:</strong></p>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721798049840/570e44ed-09e2-420c-bb37-8f5a545e9c89.png" alt class="image--center mx-auto" /></p>
<ol start="3">
<li><p><strong><em>Systemctl vs. Service:</em></strong></p>
<ul>
<li>Differences between the <strong>systemctl</strong> and <strong>service</strong> commands.</li>
</ul>
</li>
</ol>
<p>    <strong>Systemctl:-</strong> It works with <strong>systemd</strong>, the newer and more modern system and service manager. Provides detailed information about the service, including logs. Manages more than just services (e.g., system states like shutdown, reboot).</p>
<p>    The syntax for systemctl is '<strong>systemctl [command] [service_name]'.</strong> For example- To check the status of Docker: '<strong>system status docker'</strong></p>
<p><strong>Service:- It</strong> works with older service managers like SysVinit and Upstart. Simpler and more traditional command structure. Simpler and more traditional command structure.</p>
<p>The syntax for service is '<strong>service [service_name] [command]</strong>'. For example- To check the status of Docker: '<strong>service docker status'</strong></p>
<h3 id="heading-additional-tasks">Additional Tasks</h3>
<ol start="4">
<li><p><strong><em>Automate Service Management</em>:</strong></p>
<ul>
<li>Write a script to automate the starting and stopping of Docker and Jenkins services.</li>
</ul>
</li>
</ol>
<ol>
<li>Make a file <strong>script.sh:</strong></li>
</ol>
<pre><code class="lang-basic">vim script.sh
</code></pre>
<ol start="2">
<li>Write a script:</li>
</ol>
<pre><code class="lang-basic">#!/bin/bash

# Function <span class="hljs-keyword">to</span> start services
start_services() {
    echo <span class="hljs-string">"Starting Docker and Jenkins services..."</span>
    sudo systemctl start docker
    sudo systemctl start jenkins
    echo <span class="hljs-string">"Services started."</span>
}

# Function <span class="hljs-keyword">to</span> <span class="hljs-keyword">stop</span> services
stop_services() {
    echo <span class="hljs-string">"Stopping Docker and Jenkins services..."</span>
    sudo systemctl <span class="hljs-keyword">stop</span> docker
    sudo systemctl <span class="hljs-keyword">stop</span> jenkins
    echo <span class="hljs-string">"Services stopped."</span>
}
# Check <span class="hljs-keyword">if</span> the user provided an argument
<span class="hljs-keyword">if</span> [ $# -eq <span class="hljs-number">0</span> ]; <span class="hljs-keyword">then</span>
    usage
fi

# Handle the <span class="hljs-keyword">input</span> argument
case <span class="hljs-string">"$1"</span> in
    start)
        start_services
        ;;
    <span class="hljs-keyword">stop</span>)
        stop_services
        ;;
esac
</code></pre>
<ol start="3">
<li>Make the file executable:</li>
</ol>
<pre><code class="lang-basic">chmod <span class="hljs-number">700</span> script.sh
</code></pre>
<ol start="4">
<li>Run the script:</li>
</ol>
<pre><code class="lang-basic">./script.sh start
<span class="hljs-keyword">OR</span>
./script.sh <span class="hljs-keyword">stop</span>
</code></pre>
<ol start="5">
<li><p><strong><em>Enable and Disable Services:</em></strong></p>
<ul>
<li><p>Use systemctl to enable Docker to start on boot and disable Jenkins from starting on boot.</p>
<p>  <strong>Enable Docker to start on boot:</strong></p>
<pre><code class="lang-basic">  sudo systemctl enable docker
</code></pre>
<p>  <strong>Disable Jenkins from starting on boot:</strong></p>
<pre><code class="lang-basic">  sudo systemctl disable jenkins
</code></pre>
</li>
</ul>
</li>
<li><p><strong><em>Analyze Logs:</em></strong></p>
<ul>
<li>Use journalctl to analyze the logs of the Docker and Jenkins services.</li>
</ul>
</li>
</ol>
<ol>
<li><p><strong>Analyze Docker logs:</strong></p>
<pre><code class="lang-basic"> sudo journalctl -u docker
</code></pre>
</li>
<li><p><strong>Analyze Jenkins logs:</strong></p>
<pre><code class="lang-basic"> sudo journalctl -u jenkins
</code></pre>
</li>
</ol>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>Linux package managers and systemd (with systemctl) form the backbone of software and service management in modern Linux distributions. Package managers ensure that software installations are handled smoothly and consistently, managing dependencies and updates efficiently. Meanwhile, systemd and systemctl provide robust tools for controlling and managing system services, enhancing system reliability and maintainability. Understanding these tools is crucial for effective Linux system administration.</p>
<p>HAPPY LEARNING!</p>
]]></content:encoded></item><item><title><![CDATA[DAY 6: Understanding Access Control Lists (ACL's) and Special File Permissions in Linux]]></title><description><![CDATA[What is ACL?
Access control list (ACL) provides an additional, more flexible permission mechanism for file systems. ACLs allow you to define different permissions for different users or groups beyond the standard owner/group/others model.
Using 'getf...]]></description><link>https://belwalrakshita08.hashnode.dev/day-6-understanding-access-control-lists-acls-and-special-file-permissions-in-linux</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/day-6-understanding-access-control-lists-acls-and-special-file-permissions-in-linux</guid><category><![CDATA[#90daysofdevops]]></category><category><![CDATA[#TWS]]></category><category><![CDATA[Devops]]></category><category><![CDATA[access control]]></category><category><![CDATA[#shubhamLondhe]]></category><category><![CDATA[learning]]></category><category><![CDATA[AWS]]></category><category><![CDATA[permissions]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Mon, 22 Jul 2024 15:12:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721660617105/99ef6588-9bdb-4f9e-97eb-b46015c08f1f.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-what-is-acl"><strong>What is ACL?</strong></h2>
<p>Access control list (ACL) provides an additional, more flexible permission mechanism for file systems. ACLs allow you to define different permissions for different users or groups beyond the standard owner/group/others model.</p>
<p>Using '<strong><em>getfacl</em></strong> ' and '<strong><em>setfacl</em></strong> '</p>
<p><strong>setfacl</strong> and <strong>getfacl</strong> are used for setting up ACL and showing ACL respectively.</p>
<ul>
<li>'<strong><em>getfacl '</em></strong></li>
</ul>
<p>The <strong>getfacl</strong> command is used to display the ACLs of a file or directory. This command shows the effective permissions of users and groups, as well as the default ACLs if they are set.</p>
<p>To display the ACLs of a file named <strong>rakshita.txt</strong>, we would use:</p>
<pre><code class="lang-basic">getfacl rakshita.txt
</code></pre>
<p>The output is:</p>
<pre><code class="lang-basic"># file: rakshita.txt
# owner: ubuntu
# group: ubuntu
user::rw-
group::rw-
other::r--
</code></pre>
<ul>
<li><p># file: rakhsita.txt- The file we're looking at is named rakshita.txt.</p>
</li>
<li><p># ubuntu: ubuntu: The user who owns this file is ubuntu.</p>
</li>
<li><p># group: ubuntu: The group associated with this file is ubuntu.</p>
</li>
<li><p>user: :rw-: The owner (ubuntu) has:</p>
<ul>
<li><p>Read (r) permission: Can view the file.</p>
</li>
<li><p>Write (w) permission: Can modify the file.</p>
</li>
<li><p>No execute (-) permission: Cannot run the file as a program.</p>
</li>
</ul>
</li>
<li><p>group: :rw-: The group (ubuntu) has:</p>
<ul>
<li><p>Read (r) permission: Can view the file.</p>
</li>
<li><p>Write (w) permission: Can modify the file.</p>
</li>
<li><p>No execute (-) permission: Cannot run the file as a program.</p>
</li>
</ul>
</li>
<li><p>other: :r--: All other users have:</p>
<ul>
<li><p>Read (r) permission: Can view the file.</p>
</li>
<li><p>No write (-) permission: Cannot modify the file.</p>
</li>
<li><p>No execute (-) permission: Cannot run the file as a program.</p>
</li>
</ul>
</li>
<li><p>'<strong><em>setfacl '</em></strong></p>
</li>
</ul>
<p>The <strong>setfacl</strong> command is used to set or modify the ACLs of a file or directory.</p>
<ul>
<li><p>To add permissions for user:</p>
<pre><code class="lang-basic">  setfacl -m <span class="hljs-string">"u:user:permissions"</span> /path/<span class="hljs-keyword">to</span>/file
</code></pre>
</li>
<li><p>To add permissions for a group:</p>
<pre><code class="lang-basic">  setfacl -m <span class="hljs-string">"g:group:permissions"</span> /path/<span class="hljs-keyword">to</span>/file
</code></pre>
</li>
<li><p>Remove a Specific ACL Entry:</p>
<pre><code class="lang-basic">    setfacl -x u:username /path/<span class="hljs-keyword">to</span>/file
</code></pre>
</li>
<li><p>To remove all entries:</p>
</li>
</ul>
<pre><code class="lang-basic">setfacl -b path/<span class="hljs-keyword">to</span>/file
</code></pre>
<h3 id="heading-task-create-a-directory-and-set-specific-acl-permissions-for-different-users-and-groups-verify-the-permissions-using-getfacl"><strong>Task: Create a directory and set specific ACL permissions for different users and groups. Verify the permissions using ''getfacl".</strong></h3>
<ol>
<li><p>Create a directory:</p>
<pre><code class="lang-basic"> <span class="hljs-keyword">mkdir</span> control
</code></pre>
</li>
<li><p>Grant read and write permissions to user1:</p>
<pre><code class="lang-basic"> setfacl -m u:user1:rw control
</code></pre>
</li>
<li><p>Grant read-only permissions to user2:</p>
<pre><code class="lang-basic"> setfacl -m u:user2:r control
</code></pre>
</li>
<li><p>Grant read and execute permissions to group1:</p>
<pre><code class="lang-basic"> setfacl -m g:group1:rx control
</code></pre>
</li>
</ol>
<p>To verify the ACL permissions set on <strong>control</strong>, use the <strong>getfacl</strong> command:</p>
<pre><code class="lang-basic">getfacl control
</code></pre>
<p>Output:</p>
<pre><code class="lang-basic"># file: control
# owner: ubuntu
# group: ubuntu
user::rwx
user:user1:rw-
user:user2:r--
group::rwx
group:group1:r-x
mask::rwx
other::r-x
</code></pre>
<h2 id="heading-additional-task"><strong>ADDITIONAL TASK:</strong></h2>
<h3 id="heading-task-create-a-script-that-changes-the-permissions-of-multiple-files-in-a-directory-based-on-user-input"><strong>Task:</strong> <strong>Create a script that changes the permissions of multiple files in a directory based on user input.</strong></h3>
<p>Create a file:</p>
<pre><code class="lang-basic">vim permissions.sh
</code></pre>
<p>Enter the bash secript int the file:</p>
<pre><code class="lang-basic">#!/bin/bash

echo <span class="hljs-string">"enter the directory path"</span>
<span class="hljs-keyword">read</span> directory_path

echo <span class="hljs-string">"enter permissions"</span>
<span class="hljs-keyword">read</span> permissions

chmod $permissions $directory_path
echo <span class="hljs-string">"permissions changed successfully"</span>
</code></pre>
<p>Change the file permssions to make it executable:</p>
<pre><code class="lang-basic">chmod <span class="hljs-number">700</span> permissions.sh
</code></pre>
<p>Run the file:</p>
<pre><code class="lang-basic">./permissions.sh
</code></pre>
<h2 id="heading-understanding-sticky-bit-suid-and-sgid"><strong>Understanding Sticky Bit, SUID, and SGID</strong></h2>
<ol>
<li><p><strong>Sticky Bit:</strong> A Sticky bit is a permission bit that is set on a file or a directory that lets only the owner of the file/directory or the root user to delete or rename the file.</p>
</li>
<li><p><strong>SUID:</strong> SUID (Set User ID) is a special permission in Linux that allows a program to run with the permissions of the file's owner.</p>
</li>
</ol>
<p><strong>SGID:</strong> SGID (Set Group ID) is a special permission in Linux that affects both files and directories, but it works differently for each.</p>
<p>When SGID is set on an executable file, the program runs with the permissions of the file's group, rather than the user's group.</p>
<p>When SGID is set on a directory, any files created within that directory inherit the group ownership of the directory, rather than the group ownership of the user who created the file.</p>
<h3 id="heading-task-create-examples-demonstrating-the-use-of-sticky-bit-suid-and-sgid"><strong>Task: Create examples demonstrating the use of sticky bit, SUID, and SGID.</strong></h3>
<ol>
<li><p>To set the sticky bit permission on a directory, use the chmod command</p>
<p> The numeric value for the sticky bit is 1.</p>
<p> If you want to set the sticky bit permission on a directory named <strong>public</strong> with permission bits 777, run:</p>
</li>
</ol>
<pre><code class="lang-basic">chmod <span class="hljs-number">1777</span> public
</code></pre>
<ol start="2">
<li><p>The numeric value for SUID is 4.</p>
<p> If you want to set the SUID permission on a file named <strong>script.sh</strong> that currently has the permission bits 755, you would run:</p>
</li>
</ol>
<pre><code class="lang-basic">chmod <span class="hljs-number">4755</span> script.sh
</code></pre>
<ol start="3">
<li><p>The numeric value for SGID is 2.</p>
<p> If you want to set the SGID permission on a directory named shared with permission bits 755, you would execute:</p>
</li>
</ol>
<pre><code class="lang-basic">chmod <span class="hljs-number">2755</span> shared
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Day 5:  Advanced Linux Shell Scripting for DevOps Engineers with User Management]]></title><description><![CDATA[Create Directories Using Shell Script:

Write a bash script create_directories.sh that, when executed with three arguments (directory name, start number of directories, and end number of directories), creates a specified number of directories with a ...]]></description><link>https://belwalrakshita08.hashnode.dev/day-5-advanced-linux-shell-scripting-for-devops-engineers-with-user-management</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/day-5-advanced-linux-shell-scripting-for-devops-engineers-with-user-management</guid><category><![CDATA[#90daysofdevops]]></category><category><![CDATA[Devops]]></category><category><![CDATA[TrainWithShubham]]></category><category><![CDATA[#TWS]]></category><category><![CDATA[Linux]]></category><category><![CDATA[#shubhamLondhe]]></category><category><![CDATA[shell]]></category><category><![CDATA[shell scripting]]></category><category><![CDATA[learning]]></category><category><![CDATA[Hashnode]]></category><category><![CDATA[LinkedIn]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Sat, 20 Jul 2024 17:46:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721497184087/18fb8ce1-a3cb-4b4b-83d0-64bb51f1a728.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-create-directories-using-shell-script"><strong>Create Directories Using Shell Script:</strong></h2>
<ol>
<li><p>Write a bash script <a target="_blank" href="http://createDirectories.sh"><code>create_directories.sh</code></a> that, when executed with three arguments (directory name, start number of directories, and end number of directories), creates a specified number of directories with a dynamic directory name.</p>
<ul>
<li>When executed as <code>./</code><a target="_blank" href="http://createDirectories.sh"><code>create_directories.sh</code></a> <code>day 1 90</code>, it creates 90 directories as <code>day1 day2 day3 ... day90</code>.</li>
</ul>
</li>
</ol>
<pre><code class="lang-basic">    #!/bin/bash

    dir_name=$<span class="hljs-number">1</span>
    start_day=$<span class="hljs-number">2</span>
    end_day=$<span class="hljs-number">3</span>

    <span class="hljs-keyword">mkdir</span> $(eval echo $dir_name{$start_day..$end_day})
</code></pre>
<p>    Make this file executable:</p>
<pre><code class="lang-basic">    chmod <span class="hljs-number">700</span> create_directories.sh
</code></pre>
<p>    Run the file:</p>
<pre><code class="lang-basic">    ./create_directories.sh day <span class="hljs-number">1</span> <span class="hljs-number">90</span>
</code></pre>
<p>    Then list the directories:</p>
<pre><code class="lang-basic">    ls
</code></pre>
<h2 id="heading-understanding-cron-and-crontab-automating-tasks-on-linux"><strong>Understanding Cron and Crontab : Automating Tasks on Linux</strong></h2>
<p>In the world of Linux, <strong>cron</strong> and <strong>crontab</strong> are essential tools for automating repetitive tasks. Whether you're a developer, a system administrator, or just a Linux enthusiast, knowing how to use these tools can save you time and effort.</p>
<p><strong><em>What is Cron?</em></strong></p>
<p>Cron is a time-based job scheduler in Unix-like operating systems. It runs in the background and executes commands at specified times and dates. Think of it as a personal assistant that handles your routine tasks for you.</p>
<p><strong><em>What is Crontab?</em></strong></p>
<p>Crontab (short for "cron table") is a file that contains the schedule of cron jobs. Each user can have their own crontab file, which lists the commands to be run and the times they should be executed.</p>
<h3 id="heading-structure-of-a-crontab-entry">Structure of a Crontab Entry</h3>
<p>A typical crontab entry looks like this:</p>
<pre><code class="lang-basic">* * * * * command_to_be_executed
- - - - -
| | | | |
| | | | +----- Day of the week (<span class="hljs-number">0</span> - <span class="hljs-number">7</span>) (Sunday is both <span class="hljs-number">0</span> <span class="hljs-keyword">and</span> <span class="hljs-number">7</span>)
| | | +------- Month (<span class="hljs-number">1</span> - <span class="hljs-number">12</span>)
| | +--------- Day of the month (<span class="hljs-number">1</span> - <span class="hljs-number">31</span>)
| +----------- Hour (<span class="hljs-number">0</span> - <span class="hljs-number">23</span>)
+------------- Minute (<span class="hljs-number">0</span> - <span class="hljs-number">59</span>)
</code></pre>
<p>Each asterisk represents a field for time and date, and they can be replaced with specific values.</p>
<h2 id="heading-understanding-user-management"><strong>Understanding User Management</strong></h2>
<p>User management in Linux involves creating, modifying, and deleting user accounts. These accounts are essential for defining permissions, access levels, and individual user environments.</p>
<p><strong><em>Creating and Managing User Accounts</em></strong></p>
<ol>
<li><strong>Adding a New User</strong></li>
</ol>
<p>To add a new user, you can use the <strong>useradd</strong> command followed by the username. For example:</p>
<pre><code class="lang-basic">sudo useradd rakshita
</code></pre>
<ol start="2">
<li><strong>Setting a Password</strong></li>
</ol>
<p>After creating a user, set a password using the <strong>passwd</strong> command:</p>
<pre><code class="lang-basic">sudo passwd rakshita
</code></pre>
<ol start="4">
<li><strong>Deleting a User</strong></li>
</ol>
<p>To delete a user and their home directory, use the <strong>userdel</strong> command with the -r flag:</p>
<pre><code class="lang-basic">sudo userdel -r rakshita
</code></pre>
<p><strong><em>Managing Groups</em></strong></p>
<ol>
<li><strong>Adding a New Group</strong></li>
</ol>
<p>To add a new group, use the <strong>groupadd</strong> command:</p>
<pre><code class="lang-basic">sudo groupadd devops
</code></pre>
<ol start="2">
<li><strong>Adding a User to a Group</strong></li>
</ol>
<p>To add a user to a group, use the <strong>usermod</strong> command with the <strong>-aG</strong> flags:</p>
<pre><code class="lang-basic">sudo usermod -aG devops rakshita
</code></pre>
<ol start="3">
<li><strong>Viewing Group Membership</strong></li>
</ol>
<p>To view the groups a user belongs to, use the <strong>groups</strong> command:</p>
<pre><code class="lang-basic">groups rakshita
</code></pre>
<h2 id="heading-understanding-permissions"><strong>Understanding Permissions</strong></h2>
<p>Linux file permissions are represented by a set of three characters for the owner, group, and others. For example:</p>
<pre><code class="lang-basic">-rw-r--r--
</code></pre>
<p>The first character represents the file type ('<strong><em>-'</em></strong> for regular files, '<strong><em>d</em></strong>' for directories). The next nine characters are divided into three sets of three:</p>
<ol>
<li><p><strong>Owner permissions</strong> (rw-): Read and write.</p>
</li>
<li><p><strong>Group permissions</strong> (r--): Read-only.</p>
</li>
<li><p><strong>Other permissions</strong> (r--): Read-only.</p>
</li>
</ol>
<p><strong>Permission Types</strong></p>
<ul>
<li><p><strong>r</strong>: Read permission. The file can be read.</p>
</li>
<li><p><strong>w</strong>: Write permission. The file can be modified.</p>
</li>
<li><p><strong>x</strong>: Execute permission. The file can be executed as a program.</p>
</li>
</ul>
<h3 id="heading-viewing-file-permissions">Viewing File Permissions</h3>
<p>To view the permissions of a file or directory, use the <strong>'ls -l'</strong> command:</p>
<pre><code class="lang-basic">ls -l &lt;filename&gt;
</code></pre>
<p>This will display the permissions, owner, group, and other details about the file.</p>
<h3 id="heading-changing-file-permissions"><strong>Changing File Permissions</strong></h3>
<p>The <strong>'<em>chmod'</em></strong> command is used to change the permissions of a file or directory.There are two ways to use <strong>chmod</strong>: symbolic mode and numeric mode.</p>
<h4 id="heading-symbolic-mode"><strong>Symbolic Mode</strong></h4>
<p>In symbolic mode, you use letters to specify the changes:</p>
<ul>
<li><p><code>u</code> for user (owner)</p>
</li>
<li><p><code>g</code> for group</p>
</li>
<li><p><code>o</code> for others</p>
</li>
<li><p><code>a</code> for all</p>
</li>
</ul>
<p>For example, to add execute permission for the owner:</p>
<pre><code class="lang-basic">chmod u+x &lt;filename&gt;
</code></pre>
<p>To remove write permission for the group:</p>
<pre><code class="lang-basic">chmod g-w &lt;filename&gt;
</code></pre>
<h4 id="heading-numeric-mode"><strong>Numeric Mode</strong></h4>
<p>In numeric mode, you use a three-digit number to set the permissions. Each digit represents a different category of users (owner, group, others) and is the sum of the values for read (4), write (2), and execute (1) permissions.</p>
<p>For example:</p>
<ul>
<li><p>'7' (4+2+1) gives read, write, and execute permissions.</p>
</li>
<li><p>'5' (4+1) gives read and execute permissions.</p>
</li>
<li><p>'4' gives read permission only.</p>
</li>
</ul>
<p>To set the permissions to <strong>rwxr-xr--</strong> (755):</p>
<pre><code class="lang-basic">chmod <span class="hljs-number">755</span> &lt;filename&gt;
</code></pre>
<p><strong>Using 'chown' and 'chgrp'</strong></p>
<p>The '<strong><em>chown</em></strong>' command changes the owner of a file or directory:</p>
<pre><code class="lang-basic">sudo chown &lt;newowner&gt; &lt;filename&gt;
</code></pre>
<p>The '<strong><em>chgrp</em></strong>' command changes the group of a file or directory:</p>
<pre><code class="lang-basic">sudo chgrp &lt;newgroup&gt; &lt;filename&gt;
</code></pre>
<p>We can also change both the owner and group at the same time:</p>
<pre><code class="lang-basic">sudo chown &lt;newowner&gt;:&lt;newgroup&gt; &lt;filename&gt;
</code></pre>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<p>Mastering user and file management in Linux is essential for maintaining a secure and efficient system. We explored how to create and manage users and groups using commands like <strong>useradd</strong>, <strong>usermod</strong>, and <strong>groupadd</strong>. We delved into file permissions, understanding how to view and modify them using <strong>chmod</strong>, both in symbolic and numeric modes.</p>
<p>By applying these concepts, you can ensure your Linux environment is well-organized and secure. Whether you're a beginner or an experienced user, these skills are fundamental to effective Linux system administration.</p>
<p>Happy managing, and keep exploring the powerful world of Linux! If you have any questions or tips, feel free to share them in the comments.</p>
<p>HAPPY LEARNING🚀</p>
]]></content:encoded></item><item><title><![CDATA[Day 4: Basic Linux Shell Scripting for DevOps engineers]]></title><description><![CDATA[What is Linux Shell Scripting?


Shell scripting is a text file with a list of commands that instructs an operating system to perform certain tasks. A shell is an interface that interprets, processes, and executes these commands from the shell script...]]></description><link>https://belwalrakshita08.hashnode.dev/day-4-basic-linux-shell-scripting-for-devops-engineers</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/day-4-basic-linux-shell-scripting-for-devops-engineers</guid><category><![CDATA[#90daysofdevops]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Linux]]></category><category><![CDATA[learning]]></category><category><![CDATA[shell]]></category><category><![CDATA[shell script]]></category><category><![CDATA[#shubhamLondhe]]></category><category><![CDATA[#TWS]]></category><category><![CDATA[Hashnode]]></category><category><![CDATA[Learning Journey]]></category><category><![CDATA[AWS]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Fri, 19 Jul 2024 11:31:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721465089132/40c3fc81-383d-4eb4-8ba0-d6c3422d4cb8.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ol>
<li><h3 id="heading-what-is-linux-shell-scripting"><strong>What is Linux Shell Scripting?</strong></h3>
</li>
</ol>
<p>Shell scripting is a text file with a list of commands that instructs an operating system to perform certain tasks. A shell is an interface that interprets, processes, and executes these commands from the shell script. It can be particularly helpful to automate repetitive tasks, helping to save time and reduce human error. Each shell script is saved with <strong>.sh</strong> file extension e.g., <strong>myscript.sh.</strong></p>
<ol start="2">
<li><h3 id="heading-what-shell-scripting-means-for-devops"><strong>What Shell Scripting means for DevOps?</strong></h3>
</li>
</ol>
<p>Shell Scripting in DevOps means using scripts to automate repetitive tasks and make system management easier and more efficient. This helps DevOps engineers save time and ensure tasks are done consistently.</p>
<p><strong>What Does Shell Scripting Do in DevOps?</strong></p>
<ol>
<li><p><strong>Automates Tasks</strong>: Instead of doing tasks manually, you write a script to do them for you.</p>
</li>
<li><p><strong>Saves Time</strong>: Once a script is written, you can run it anytime to perform the same task quickly.</p>
</li>
<li><p><strong>Reduces Errors</strong>: Automating tasks minimizes the chances of making mistakes.</p>
</li>
<li><p><strong>Ensures Consistency</strong>: Scripts perform tasks the same way every time, ensuring uniform results.</p>
</li>
<li><h3 id="heading-what-isbinbash-can-we-writebinshas-well"><strong>What is</strong><code>#!/bin/bash</code><strong>? Can we write</strong><code>#!/bin/sh</code><strong>as well?</strong></h3>
</li>
</ol>
<p>The line "#! /bin/bash" is called a <strong>shebang</strong>. It indicates the path to the interpreter that should be used to execute the script, in this case, "/bin/bash" for the Bash shell. It ensures that the script is interpreted by the specified shell, in this case, Bash. This line is placed at the beginning of a script to define the interpreter for proper execution.</p>
<p>Yes, we can write #!/bin/sh, but there are some differences to keep in mind:</p>
<ol>
<li><p><strong>Compatibility:</strong></p>
<ul>
<li><p><strong>#!/bin/sh</strong> scripts are more portable because <strong>sh</strong> is available on all Unix-like systems.</p>
</li>
<li><p>Some advanced features of Bash may not be available or may behave differently in <strong>sh</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>Features:</strong></p>
<ul>
<li><p><strong>#!/bin/bash</strong> gives you access to all Bash-specific features, such as arrays, certain string operations, and more advanced scripting capabilities.</p>
</li>
<li><p><strong>#!/bin/sh</strong> ensures that the script uses only the more basic features of the shell language, which can help make the script more portable across different systems.</p>
</li>
</ul>
</li>
<li><h3 id="heading-write-a-shell-script-that-printsi-will-complete-90daysofdevops-challenge"><strong>Write a Shell Script that prints</strong><code>I will complete #90DaysOfDevOps challenge</code><strong>.</strong></h3>
</li>
</ol>
<p>Open a text editor and create a file <strong>script.sh:</strong></p>
<pre><code class="lang-basic">vim script.sh
</code></pre>
<p>Press i, add shebang and the script to be printed:</p>
<pre><code class="lang-basic">#!/bin/bash

echo <span class="hljs-string">"I will complete #90DaysOfDevOps challenge."</span>
</code></pre>
<p>To save and exit, press '<strong>esc', ':wq'</strong> and <strong>'enter'.</strong></p>
<p>Make the script executable for user/owner only:</p>
<pre><code class="lang-basic">chmod <span class="hljs-number">700</span> script.sh
</code></pre>
<p>Run the script:</p>
<pre><code class="lang-basic">./script.sh
</code></pre>
<ol start="6">
<li><h3 id="heading-write-a-shell-script-that-takes-user-input-input-from-arguments-and-prints-the-variables"><strong>Write a Shell Script that takes user input, input from arguments, and prints the variables?</strong></h3>
</li>
</ol>
<p>Create a <strong>arguments.sh</strong> file:</p>
<pre><code class="lang-basic">vim arguments.sh
</code></pre>
<p>Enter the script:</p>
<pre><code class="lang-basic">#!/bin/bash

# Take_user_input
echo <span class="hljs-string">"Enter your name:"</span>
<span class="hljs-keyword">read</span> user_input

# Input_from_argumemnts
arg1=$<span class="hljs-number">1</span>
arg2=$<span class="hljs-number">2</span>

# Print_variables
echo <span class="hljs-string">"User input: $user_input"</span>
echo <span class="hljs-string">"First argument: $arg1"</span>
echo <span class="hljs-string">"Second argument: $arg2"</span>
</code></pre>
<p>Save and quit the file. Then change file permissions to make it executable by the user:</p>
<pre><code class="lang-basic">chmod <span class="hljs-number">700</span> arguments.sh
</code></pre>
<p>Run the script:</p>
<pre><code class="lang-basic">./arguments.sh <span class="hljs-number">1</span> <span class="hljs-number">2</span>
</code></pre>
<p>Here;</p>
<ul>
<li><p>1= argument 1 value.</p>
</li>
<li><p>2= argument 2 value.</p>
</li>
</ul>
<ol start="7">
<li><h3 id="heading-provide-an-example-of-an-if-else-statement-in-shell-scripting-by-comparing-two-numbers"><strong>Provide an example of an If-Else statement in Shell Scripting by comparing two numbers?</strong></h3>
</li>
</ol>
<pre><code class="lang-basic">#!/bin/bash

# Define two numbers
num1=<span class="hljs-number">5</span>
num2=<span class="hljs-number">10</span>

# Compare the numbers
<span class="hljs-keyword">if</span> [ $num1 -gt $num2 ]; <span class="hljs-keyword">then</span>

    echo <span class="hljs-string">"Number 1 ($num1) is greater than Number 2 ($num2)"</span>

elif [ $num1 -lt $num2 ]; <span class="hljs-keyword">then</span>

    echo <span class="hljs-string">"Number 1 ($num1) is less than Number 2 ($num2)"</span>
<span class="hljs-keyword">else</span>

    echo <span class="hljs-string">"Number 1 ($num1) is equal to Number 2 ($num2)"</span>
fi
</code></pre>
<p>Run the script.</p>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<p>We learned about basic Linux Shell Scripting and its fundamentals, which are essential to strengthen our foundation in Shell Scripting. We can write and practice more Shell commands and scripting on our own and by taking references from the internet.</p>
<p>Stay tuned for more in my #90daysdevops journey!</p>
<p>Happy Learning!✨</p>
]]></content:encoded></item><item><title><![CDATA[Day 3: Basic Linux commands with a twist]]></title><description><![CDATA[View the content of a file and display line numbers

To display the content of file with line numbers in Linux, we use 'cat' command with the '-n' option.
cat -n filename.txt


Change the access permissions of files to make them readable, writable, a...]]></description><link>https://belwalrakshita08.hashnode.dev/day-3-basic-linux-commands-with-a-twist</link><guid isPermaLink="true">https://belwalrakshita08.hashnode.dev/day-3-basic-linux-commands-with-a-twist</guid><category><![CDATA[#90daysofdevops]]></category><category><![CDATA[Devops]]></category><category><![CDATA[#TWS]]></category><category><![CDATA[Hashnode]]></category><category><![CDATA[Linux]]></category><category><![CDATA[linux-basics]]></category><category><![CDATA[linux-commands]]></category><category><![CDATA[learning]]></category><category><![CDATA[Learning Journey]]></category><dc:creator><![CDATA[Rakshita Belwal]]></dc:creator><pubDate>Thu, 18 Jul 2024 13:14:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721308467331/e431254a-5d12-457b-a909-82d8f8fa90cc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ol>
<li><strong><em>View the content of a file and display line numbers</em></strong></li>
</ol>
<p>To display the content of file with line numbers in Linux, we use '<em>cat</em>' command with the '<em>-n</em>' option.</p>
<pre><code class="lang-basic">cat -n filename.txt
</code></pre>
<ol start="2">
<li><strong><em>Change the access permissions of files to make them readable, writable, and executable by the owner only?</em></strong></li>
</ol>
<p>To change the access permissions of file so that it is readable, writable and executable by the owner only, we use '<em>chmod'</em> command with <em>'700</em>' mode.</p>
<pre><code class="lang-basic">chmod <span class="hljs-number">700</span> filename.txt
</code></pre>
<p>Here's what <code>700</code> means:</p>
<ul>
<li><p>'7' for the owner: read (4), write (2), and execute (1) permissions (4+2+1 = 7).</p>
</li>
<li><p>'0' for the group: no permissions.</p>
</li>
<li><p>'0' for others: no permissions.</p>
</li>
</ul>
<ol start="3">
<li><strong><em>Check the last 10 commands you have run?</em></strong></li>
</ol>
<p>The '<em>history</em>' command is generally used to display all the commands we used. By default, it shows all the commands we've run in the current session, but we can filter it to show only the last 10 commands:</p>
<pre><code class="lang-basic">history | tail -n <span class="hljs-number">10</span>
</code></pre>
<p>Here’s what each part of this command does:</p>
<ul>
<li><p>history: Displays the command history.</p>
</li>
<li><p>|: Pipes the output of history to another command.</p>
</li>
<li><p>tail -n 10: Shows the last 10 lines of the piped output.</p>
</li>
</ul>
<ol start="4">
<li><strong><em>Remove a directory and all its contents?</em></strong></li>
</ol>
<p>To remove a directory and all its contents, we use '<em>rm</em>' command with the '<em>-r</em>' (recursive) option.</p>
<pre><code class="lang-basic">rm -r directory_name
</code></pre>
<ol start="5">
<li><strong><em>Create a</em></strong><code>fruits.txt</code><strong><em>file, add content (one fruit per line), and display the content?</em></strong></li>
</ol>
<p>To create a file in Linux, we can use '<em>touch</em>' command or directly open the file with a text editor like '<em>nano</em>' or '<em>vim</em>'.</p>
<p><strong>Creating a file (fruits.txt):</strong></p>
<p>Using '<em>touch</em>'</p>
<pre><code class="lang-basic">touch fruits.txt
</code></pre>
<p><strong>Adding content to 'fruits.txt':</strong></p>
<p>Using text editor '<em>vim</em>'</p>
<pre><code class="lang-basic">vim fruits.txt
</code></pre>
<p>After using above (vim) command we can add contents in '<em>fruits.txt</em>' file. <strong>(Write different fruits name per line).</strong> To save and exit the file, press '<em>esc'</em> then '<em>:wq'</em> and '<em>enter</em>'.</p>
<p><strong>Display the content of fruits.txt:</strong></p>
<p>Using '<em>cat</em>' command</p>
<pre><code class="lang-basic">cat fruits.txt
</code></pre>
<ol start="6">
<li><strong><em>Add content in</em></strong><code>devops.txt</code><strong><em>(one in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava. Then, append "Pineapple" to the end of the file?</em></strong></li>
</ol>
<p>We can use text editor like 'vim' to create and enter fruits directly:</p>
<pre><code class="lang-basic">vim devops.txt
</code></pre>
<p>In the text editor, add the following lines:</p>
<pre><code class="lang-basic">Apple
Mango
Banana
Cherry
Kiwi
Orange
Guava
</code></pre>
<p>To save and exit the file, press '<em>esc'</em> then '<em>:wq'</em> and '<em>enter</em>'.</p>
<p>To append "Pineapple" to the file, use '<em>echo</em>' command with the append operator '<em>&gt;&gt;</em>'.</p>
<pre><code class="lang-basic">echo <span class="hljs-string">"Pineapple"</span> &gt;&gt; devops.txt
</code></pre>
<p>To verify use '<em>cat</em>' command</p>
<pre><code class="lang-basic">cat devops.txt
</code></pre>
<ol start="7">
<li><strong><em>Show the first three fruits from the file in reverse order?</em></strong></li>
</ol>
<p>To show first three fruits from file we use '<em>head</em>' command</p>
<pre><code class="lang-basic">head -n <span class="hljs-number">3</span> devops.txt
</code></pre>
<p>The '<em>head -n 3 devops.txt</em>' command will output:</p>
<pre><code class="lang-basic">Apple 
Mango 
Banana
</code></pre>
<p>To reverse the order of the first three lines, we’ll use a combination of the '<em>head'</em> and '<em>tac</em>' commands. The '<em>tac</em>' command is the reverse of the '<em>cat'</em> command and displays lines in reverse order:</p>
<pre><code class="lang-basic">head -n <span class="hljs-number">3</span> devops.txt | tac
</code></pre>
<p>This command first takes the top three lines of the file and then reverses their order. The output will be:</p>
<pre><code class="lang-basic">Banana
Mango
Apple
</code></pre>
<ol start="8">
<li><strong><em>Show the bottom three fruits from the file, and then sort them alphabetically?</em></strong></li>
</ol>
<p>To display the bottom three lines of the devops.txt file, we can use the '<em>tail</em>' command</p>
<pre><code class="lang-basic">tail -n <span class="hljs-number">3</span> devops.txt
</code></pre>
<p>The output will be:</p>
<pre><code class="lang-basic">Orange
Guava
Pineapple
</code></pre>
<p>To sort these lines alphabetically, we can pipe the output of the '<em>tail</em>' command into the '<em>sort</em>' command:</p>
<pre><code class="lang-basic">tail -n <span class="hljs-number">3</span> devops.txt | sort
</code></pre>
<p>The output will be:</p>
<pre><code class="lang-basic">Guava
Orange 
Pineapple
</code></pre>
<ol start="9">
<li><strong><em>Create another file</em></strong><code>Colors.txt</code><strong><em>, add content (one color per line), and display the content?</em></strong></li>
</ol>
<p>To create and add content in Colors.txt we use 'vim' command:</p>
<pre><code class="lang-basic">vim Colors.txt
</code></pre>
<p>Add different colors name per line in file. To save and exit, press '<em>esc</em>' then '<em>:wq</em>' and then '<em>enter</em>'.</p>
<p>To display the content we use '<em>cat</em>' command</p>
<pre><code class="lang-basic">cat Colors.txt
</code></pre>
<ol start="10">
<li><strong><em>Add content in</em></strong><code>Colors.txt</code><strong><em>(one in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey. Then, prepend "Yellow" to the beginning of the file?</em></strong></li>
</ol>
<p>To add content in Colors.txt we use '<em>vim</em>' command</p>
<pre><code class="lang-basic">vim Colors.txt
</code></pre>
<p>Add content in above file</p>
<pre><code class="lang-basic">Red
Pink
White
Black
Blue 
Orange
Purple
Grey
</code></pre>
<p>Save and exit by pressing '<em>esc</em>', '<em>:wq' and 'enter'.</em></p>
<p>To prepend "Yellow" in the beginning of the file, we can use '<em>echo</em>' command with the append operator '<em>&gt;&gt;</em>' and a temporary file. Then, overwrite Colors.txt with the new content.</p>
<pre><code class="lang-basic">echo <span class="hljs-string">"Yellow"</span> &gt; tmp.txt
cat Colors.txt &gt;&gt; tmp.txt
mv tmp.txt Colors.txt
</code></pre>
<p>To display we use '<em>cat</em>' command</p>
<pre><code class="lang-basic">cat Colors.txt
</code></pre>
<p>The output will be:</p>
<pre><code class="lang-basic">Yellow
Red
Pink
White
Black
Blue 
Orange
Purple
Grey
</code></pre>
<ol start="11">
<li><strong><em>Find and display the lines that are common between</em></strong><code>fruits.txt</code><strong><em>and</em></strong><code>Colors.txt</code><strong><em>?</em></strong></li>
</ol>
<p>First, ensure both '<em>fruits.txt</em>' and '<em>Colors.txt</em>' are sorted alphabetically.</p>
<p>We'll use '<em>sort</em>' command to sort the content and -o flag to create new file with sorted output.</p>
<pre><code class="lang-basic">sort fruits.txt -o fruits_sorted.txt
sort Colors.txt -o Colors_sorted.txt
</code></pre>
<p>Now, use the '<em>comm</em>' command with the sorted files to find and display the common lines (in this case, common fruits/colors):</p>
<pre><code class="lang-basic">comm -<span class="hljs-number">12</span> fruits_sorted.txt Colors_sorted.txt
</code></pre>
<ul>
<li><p>-1 suppress lines unique to fruits_sorted.txt.</p>
</li>
<li><p>-2 suppress lines unique to Colors_sorted.txt.</p>
</li>
<li><p>-12 display lines common to both files.</p>
</li>
</ul>
<ol start="12">
<li><strong><em>Count the number of lines, words, and characters in both</em></strong><code>fruits.txt</code><strong><em>and</em></strong><code>Colors.txt</code><strong><em>?</em></strong></li>
</ol>
<p>We used '<em>wc</em> ' command to count the number of lines, words and characters in files.</p>
<p>For Fruits.txt:</p>
<pre><code class="lang-basic">wc fruits.txt
</code></pre>
<p>For Colors.txt:</p>
<pre><code class="lang-basic">wc Colors.txt
</code></pre>
<ul>
<li><p>The first column will represent: Number of lines.</p>
</li>
<li><p>The second column will represent: Number of words.</p>
</li>
<li><p>The third column will represent: Number of characters.</p>
</li>
</ul>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<p>We explored fundamental Linux commands for efficient file operations like: Viewing File Content with Line Numbers, Changing File Permissions, Command History Management, Directory Deletion, Creating and Manipulating Text Files, Text Manipulation and File Metrics.</p>
<p>These foundational Linux commands empower developers and system administrators to efficiently manage file operations, ensure security, and analyze data effectively. Mastering these skills enhances proficiency and productivity in Linux environments, enabling smoother workflow and robust file management capabilities.</p>
<p>Happy Learning🌟</p>
]]></content:encoded></item></channel></rss>