<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anup Ghattikar on Medium]]></title>
        <description><![CDATA[Stories by Anup Ghattikar on Medium]]></description>
        <link>https://medium.com/@aghattikar82?source=rss-f9bc72cf44af------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bLqStp-HG30XOxuvzFSjXw.png</url>
            <title>Stories by Anup Ghattikar on Medium</title>
            <link>https://medium.com/@aghattikar82?source=rss-f9bc72cf44af------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 07:38:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aghattikar82/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[2-Tier Application Deployment with Docker in One Video | Episode 2]]></title>
            <link>https://medium.com/@aghattikar82/2-tier-application-deployment-with-docker-in-one-video-episode-2-e970c943e0a0?source=rss-f9bc72cf44af------2</link>
            <guid isPermaLink="false">https://medium.com/p/e970c943e0a0</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Anup Ghattikar]]></dc:creator>
            <pubDate>Mon, 25 Sep 2023 13:10:46 GMT</pubDate>
            <atom:updated>2023-09-25T13:10:46.736Z</atom:updated>
            <content:encoded><![CDATA[<h3>2-Tier Application Deployment with Docker</h3><p>Two Tier Application Deployment,</p><p>we will be dockerizing a two-tier flask application with MySQL using these concepts:</p><p>Docker Build, Images, Containers</p><p>Docker Networking</p><p>Docker Volumes</p><p>Docker Compose</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ckIuMfFBeZWvpdZ2I1Z8zg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Y9mObiaDocSFCwmYSLdBA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qogInlO5uvXW4xachLSzJg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p5U38voDE7Txz6AoHJd65w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6A1CtM2miL5rLKA6NI3k2Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xi_6YRyue7FF4KuT8ki6tQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kW50zMCmUAGb1yOCMPx3Wg.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e970c943e0a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Tool Mastering]]></title>
            <link>https://medium.com/@aghattikar82/docker-tool-mastering-83d822e53cd8?source=rss-f9bc72cf44af------2</link>
            <guid isPermaLink="false">https://medium.com/p/83d822e53cd8</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[docker-swarm]]></category>
            <dc:creator><![CDATA[Anup Ghattikar]]></dc:creator>
            <pubDate>Wed, 06 Sep 2023 18:36:32 GMT</pubDate>
            <atom:updated>2023-09-06T18:36:32.057Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Docker?</h3><p>Docker is a platform and toolset that simplifies the process of developing, deploying, and running applications in containers.</p><h3>What is a Container?</h3><p>Containerization is a technology that allows you to package an application and its dependencies together into a single container image. This image can then be run consistently across different environments, such as development, testing, and production.</p><h3>How to install Docker In Ubuntu?</h3><p><a href="https://docs.docker.com/engine/install/ubuntu/">Docker Installation Link For Ubuntu</a></p><h3>Docker Commands?</h3><ol><li><strong>docker — version</strong>: Check the installed Docker version.</li><li><strong>docker pull &lt;image_name&gt;:&lt;tag&gt;</strong>: Download a Docker image from a registry like Docker Hub. If the tag is omitted, it defaults to “latest.”</li><li><strong>docker images</strong>: List all locally available Docker images.</li><li><strong>docker ps</strong>: List running containers.</li><li><strong>docker ps -a</strong>: List all containers, including stopped ones.</li><li><strong>docker run &lt;options&gt; &lt;image_name&gt;:&lt;tag&gt;</strong>: Create and start a container from an image. Some common options include:</li></ol><ul><li>-d: Run the container in detached mode (in the background).</li><li>-it: Start an interactive shell session in the container.</li><li>--rm: Automatically remove the container when it exits.</li><li>-p &lt;host_port&gt;:&lt;container_port&gt;: Map a port from the host to the container.</li></ul><ol><li><strong>docker stop &lt;container_id or container_name&gt;</strong>: Stop a running container.</li><li><strong>docker start &lt;container_id or container_name&gt;</strong>: Start a stopped container.</li><li><strong>docker restart &lt;container_id or container_name&gt;</strong>: Restart a running or stopped container.</li><li><strong>docker exec &lt;options&gt; &lt;container_id or container_name&gt; &lt;command&gt;</strong>: Execute a command inside a running container. Common options include -it for an interactive session.</li><li><strong>docker rm &lt;container_id or container_name&gt;</strong>: Remove a stopped container. Use the -f option to forcefully remove a running container.</li><li><strong>docker rmi &lt;image_id or image_name&gt;:&lt;tag&gt;</strong>: Remove a Docker image. Use the -f option to forcefully remove it.</li><li><strong>docker build &lt;options&gt; -t &lt;image_name&gt;:&lt;tag&gt; &lt;path_to_Dockerfile&gt;</strong>: Build a Docker image from a Dockerfile. The -t option specifies the image name and tag.</li><li><strong>docker-compose up</strong>: Start services defined in a docker-compose.yml file.</li><li><strong>docker-compose down</strong>: Stop and remove containers, networks, and volumes defined in a docker-compose.yml file.</li><li><strong>docker network ls</strong>: List Docker networks.</li><li><strong>docker volume ls</strong>: List Docker volumes.</li><li><strong>docker logs &lt;container_id or container_name&gt;</strong>: View the logs of a container.</li><li><strong>docker inspect &lt;container_id or container_name&gt;</strong>: View detailed information about a container or image.</li><li><strong>docker-compose logs</strong>: View the combined logs of services defined in a docker-compose.yml file.</li></ol><h3>How to Debug a Container?</h3><ol><li><strong>Check Container Logs</strong>:</li></ol><ul><li>Start by checking the container’s logs to see if there are any error messages or issues reported there.</li><li>Use the docker logs command to view the container&#39;s logs. For example:</li><li>docker logs &lt;container_name_or_id&gt;</li></ul><ol><li><strong>Attach to the Container</strong>:</li></ol><ul><li>You can attach to a running container to see what’s happening inside it in real-time. Use the docker exec command with the -it flag to open an interactive shell within the container:</li><li>docker exec -it &lt;container_name_or_id&gt; /bin/ba</li><li>Replace /bin/bash with the shell or command appropriate for your container&#39;s OS.</li></ul><ol><li><strong>Install Debugging Tools</strong>:</li></ol><ul><li>If your container lacks debugging tools, you can install them from within the container using the package manager relevant to the container’s OS. For example, on a Debian-based system, use apt-get, and on an Alpine Linux system, use apk.</li><li>Install necessary debugging tools like strace, netstat, or tcpdump to diagnose specific issues.</li></ul><ol><li><strong>Use Docker Inspect</strong>:</li></ol><ul><li>The docker inspect command provides detailed information about a container, including its configuration, environment variables, and network settings. This can help you identify misconfigurations.</li><li>docker inspect &lt;container_name_or_id&gt;</li></ul><ol><li><strong>Check Environment Variables</strong>:</li></ol><ul><li>Verify that the environment variables your application relies on are correctly set within the container.</li></ul><ol><li><strong>Examine Docker Networking</strong>:</li></ol><ul><li>Inspect the container’s network settings to ensure it’s properly connected to other containers or the host network.</li><li>docker network inspect &lt;network_name&gt;</li></ul><ol><li><strong>Debug Port Forwarding</strong>:</li></ol><ul><li>If your application exposes ports, ensure that port forwarding is correctly configured. Use docker port to check port mappings.</li><li>docker port &lt;container_name_or_id&gt;</li></ul><ol><li><strong>Check Container Resource Usage</strong>:</li></ol><ul><li>Use the docker stats command to monitor the container&#39;s resource usage, including CPU and memory.</li><li>docker stats &lt;container_name_or_id&gt;</li></ul><h3>What is Docker Volumes?</h3><p><strong>Docker volumes </strong>are a crucial feature in Docker, a popular containerization platform. They provide a way to manage and persist data generated by Docker containers and ensure data durability and accessibility between container instances and even after containers are stopped or removed. Docker volumes are particularly useful for scenarios where you need to store data that should survive the container’s lifecycle or when you want to share data between containers.</p><ol><li><strong>Data Persistence</strong>: Docker containers are ephemeral by design, meaning that any data generated or modified within a container is typically lost when the container is removed. Docker volumes allow you to persist data outside of the container filesystem, ensuring that the data survives even if the container is stopped or deleted.</li><li><strong>Storage Driver Agnostic</strong>: Docker volumes are storage driver agnostic, which means they can work with different storage backends, such as the local filesystem, network-attached storage (NAS), or cloud-based storage services like Amazon EBS or Azure Disk.</li><li><strong>Named and Managed</strong>: Docker volumes have names, making it easy to reference and manage them. You can create, list, inspect, and remove volumes using Docker CLI commands.</li><li><strong>Sharing Data</strong>: Volumes can be shared between multiple containers, allowing different containers to access and update the same data. This is useful for scenarios like database containers where you want to separate the database server from the data storage.</li><li><strong>Volume Types</strong>: Docker supports different types of volumes, including named volumes, host-mounted volumes, and anonymous volumes.</li></ol><ul><li><strong>Named Volumes</strong>: These are created and managed by Docker. They have names and are stored in a designated location within the Docker environment. Named volumes are typically the recommended way to manage persistent data.</li><li><strong>Host-Mounted Volumes</strong>: These involve mounting a specific directory from the host machine into a container. This allows you to use a directory from the host as the storage location for your container. This is useful when you want fine-grained control over the data location.</li><li><strong>Anonymous Volumes</strong>: These are temporary volumes that are automatically created by Docker when a container is started if no explicit volume is specified. They are not given names and can be challenging to manage for long-term data storage</li></ul><ol><li><strong>Docker Compose</strong>: When working with Docker Compose, you can define volumes in your docker-compose.yml file, making it easier to manage volumes for multi-container applications.</li></ol><p>Here are some basic Docker volume-related commands:</p><ul><li>Create a named volume: docker volume create my_volume</li><li>List volumes: docker volume ls</li><li>Inspect a volume: docker volume inspect my_volume</li><li>Remove a volume: docker volume rm my_volume</li></ul><h3>Developing with containers?</h3><ol><li><strong>Containerization Technology:</strong> <strong>Docker i</strong>s the most widely used containerization platform.</li><li><strong>Install Containerization Software:</strong> Install the containerization software (e.g., Docker) on your development machine.</li><li><strong>Create a Dockerfile:</strong> For Docker, create a Dockerfile for your application. This file contains instructions for building a container image. It typically starts with a base image and then adds your application code and dependencies.</li></ol><ul><li>DockerfileCopy code# Use an official Python runtime as a base image FROM python:3.8-slim # Set the working directory in the container WORKDIR /app # Copy your application code into the container COPY . /app # Install application dependencies RUN pip install -r requirements.txt # Specify the command to run when the container starts CMD [&quot;python&quot;, &quot;app.py&quot;]</li></ul><ol><li><strong>Build the Container Image:</strong> Use the docker build command to build a container image from your Dockerfile.</li></ol><ul><li>docker build -t myapp:latest .</li></ul><ol><li><strong>Run the Container Locally:</strong> Start a container from the image you just built using the docker run command.</li></ol><ul><li>docker run -p 8080:80 myapp:latest</li></ul><ol><li><strong>Develop Inside the Container:</strong> To develop inside the container, you can use the docker exec command to access a shell within a running container.</li></ol><ul><li>bashCopy codedocker exec -it &lt;container_id&gt; bash</li></ul><ol><li>You can edit code, install packages, and test your application from within the container.</li><li><strong>Use Docker Compose (Optional):</strong> If your application consists of multiple containers, consider using Docker Compose to define and manage your multi-container application stack.</li></ol><ul><li>version: &#39;3&#39; services: web: build: . ports: - &quot;8080:80&quot; db: image: postgres:12</li></ul><ol><li>Run your application stack with docker-compose-up.</li><li><strong>Version Control:</strong> Ensure that your Dockerfile(s) and any necessary configuration files are added to your version control system (e.g., Git) along with your application code.</li><li><strong>Continuous Integration/Continuous Deployment (CI/CD):</strong> Set up CI/CD pipelines to automate the building and deployment of containerized applications to various environments, such as development, staging, and production.</li><li><strong>Security:</strong> Pay attention to container security best practices, such as regular image scanning, least privilege access, and network segmentation.</li></ol><h3>Docker Compose-Running Multiple Services?</h3><p>Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to define a multi-service application in a single YAML file and then use the docker-compose command to start and manage all the containers that make up your application. Each service in your Docker Compose file can be thought of as a separate component of your application.</p><p>Here’s how you can define and run multiple services using Docker Compose:</p><ol><li><strong>Install Docker Compose</strong>: Ensure that you have Docker Compose installed on your system. You can download and install it from the official Docker website: <a href="https://docs.docker.com/compose/install/"><strong>Install Docker Compose</strong></a>.</li><li><strong>Create a Docker Compose File</strong>: Create a file named docker-compose.yml in your project directory. This file will define your multi-service application. Here&#39;s a basic example of a Compose file:</li></ol><ul><li>yamlCopy codeversion: &#39;3&#39; services: web: image: nginx ports: - &quot;80:80&quot; app: image: myapp ports: - &quot;8080:8080&quot;</li></ul><ol><li>In this example, we have two services, web and app. The web service uses the official Nginx image and exposes port 80, while the app service uses a custom image named myapp and exposes port 8080</li><li><strong>Start the Services</strong>: To start all the services defined in your docker-compose.yml file, run the following command in the directory where the Compose file is located:</li></ol><ul><li>bashCopy codedocker-compose up</li></ul><ol><li>This command will create and start the containers for each service.</li><li><strong>Access the Services</strong>: Once the services are running, you can access them just like you would with standalone containers.</li><li><strong>Manage the Services</strong>: Docker Compose provides various commands for managing your services, such as stopping, starting, or removing them. To stop the services, use docker-compose down. To start them again, use docker-compose up. To remove the containers and networks defined in your Compose file, use docker-compose down --volumes to also remove data volumes.</li><li><strong>Scale Services</strong>: Docker Compose also allows you to scale your services by specifying the desired number of replicas for each service. For example, to run two instances of the app service, you can use:</li></ol><ul><li>version: &#39;3&#39; services: web: image: nginx ports: - &quot;80:80&quot; app: image: myapp ports: - &quot;8080:8080&quot; scale: 2</li></ul><ol><li>Then, run docker-compose up --scale app=2 to start two instances of the app service.</li></ol><h3>Docker File — Building Own Docker Image?</h3><p>Creating a Dockerfile to build your own Docker image allows you to package your application, along with its dependencies and configuration, into a portable container. Here’s a step-by-step guide on how to create a Dockerfile and build your custom Docker image:</p><ol><li><strong>Set Up Your Project Directory:</strong> Create a directory for your project and navigate to it in your terminal. This directory will contain your Dockerfile and any other necessary files.</li><li><strong>Create a Dockerfile:</strong> Create a file named Dockerfilein your project directory. This file will contain instructions on how to build your Docker image. You can use a text editor of your choice to create and edit this file.</li><li><strong>Define a Base Image:</strong> Start your Dockerfile by specifying a base image that provides the foundational environment for your application. You can choose an official image from Docker Hub or create your base image if needed. For example, to use the official Python 3.8 image as a base:</li></ol><ul><li>FROM python:3.8</li></ul><ol><li><strong>Set the Working Directory:</strong> It’s a good practice to set the working directory within the container to make it easier to manage files and paths. You can use the WORKDIR instruction for this:</li></ol><ul><li>WORKDIR /app</li></ul><ol><li><strong>Copy Your Application Files:</strong> Use the COPY instruction to copy your application files from your local directory to the container. For example, if your application is in the current directory:</li></ol><ul><li>COPY . /app</li></ul><ol><li><strong>Install Dependencies and Configure Your Application:</strong> Depending on your application, you may need to install dependencies or configure them within the container. Use appropriate commands like RUN, ENV, or others as needed. For example, to install Python dependencies using pip:</li></ol><ul><li>RUN pip install -r requirements.txt</li></ul><ol><li><strong>Expose Ports (if necessary):</strong> If your application listens on specific ports, use the EXPOSE instructions to document which ports should be exposed. Note that this does not publish the ports; it&#39;s for documentation purposes.</li></ol><ul><li>EXPOSE 80</li></ul><ol><li><strong>Define the Command to Run Your Application:</strong> Use the CMD instruction to specify the command that should be executed when the container starts. This should typically be the command to run your application. For example:</li></ol><ul><li>CMD [&quot;python&quot;, &quot;app.py&quot;]</li></ul><ol><li><strong>Build the Docker Image:</strong> In your terminal, navigate to the directory containing your Dockerfile and run the docker build command to build your Docker image. Replace my-image with a suitable name for your image and use . to indicate the current directory:</li></ol><ul><li>docker build -t my-image .</li></ul><ol><li><strong>Run a Container from Your Image:</strong> Once the image is built, you can run a container from it using the docker run command:</li></ol><ul><li>docker run -d -p 8080:80 my-image</li></ul><p>This command runs a detached container (-d) and maps port 8080 on your host to port 80 in the container.</p><h3>Docker Topics Definitions:</h3><p><strong>Containers</strong>: Containers are lightweight, standalone, and executable packages that contain everything needed to run an application, including the code, runtime, libraries, and system tools. Docker containers are based on images.</p><p><strong>Images</strong>: An image is a read-only template used to create containers. Images are built from a set of instructions defined in a Dockerfile. You can think of an image as a snapshot of an application and its dependencies.</p><p><strong>Dockerfile</strong>: A Dockerfile is a text file that contains instructions for building a Docker image. It specifies the base image, environment variables, application code, and any other dependencies required for the application.</p><p><strong>Docker Hub</strong>: Docker Hub is a cloud-based repository for Docker images. It provides a vast collection of pre-built images that you can use as a base for your containers.</p><p><strong>Containerization</strong>: Containerization is the process of packaging an application along with its dependencies into a container. This process ensures that the application runs consistently across different environments, from development to production.</p><p><strong>Docker Compose</strong>: Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to define the services, networks, and volumes for your application stack in a single YAML file.</p><p><strong>Docker Swarm</strong>: Docker Swarm is Docker’s native clustering and orchestration solution. It allows you to create and manage a swarm of Docker nodes, making it easier to scale and manage containerized applications.</p><p><strong>Docker CLI</strong>: The Docker Command-Line Interface (CLI) is used for interacting with Docker. It provides commands for building, running, and managing containers and images.</p><p><strong>Container Registries</strong>: Container registries are repositories for storing and distributing Docker images. Docker Hub is one example, but you can also set up your private container registry for security and control.</p><p><strong>Docker Networking</strong>: Docker provides various networking options to connect containers and expose them to the host or external networks. These options include bridge networks, host networks, and overlay networks.</p><p><strong>Docker Volumes</strong>: Docker volumes are used to persist data between container runs. They allow you to separate the data from the container and ensure data durability.</p><p><strong>Docker Security</strong>: Understanding container security best practices is crucial when using Docker in production. Topics include image scanning, vulnerability assessment, and container runtime security.</p><p><strong>Docker on Windows and macOS</strong>: Docker can run on Windows and macOS using Docker Desktop, which provides a convenient way to develop and test Dockerized applications on these platforms.</p><p><strong>Docker for Continuous Integration/Continuous Deployment (CI/CD)</strong>: Docker is often integrated into CI/CD pipelines to automate the building and deployment of containerized applications.</p><p><strong>Container Orchestration and Scaling</strong>: Docker containers can be scaled horizontally to handle increased traffic or workload using tools like Docker Swarm or Kubernetes.</p><ul><li><strong>IMPORTANT LINKS:</strong></li></ul><ol><li>Docker Official Document: <a href="https://docs.docker.com/">Official Docker Website</a></li><li>Docker Tutorial Youtube With Project : <a href="https://youtu.be/3c-iBn73dDE?si=D0RNDTrsVG5h8Z1G">Youtube Link</a></li><li>GitHub Link : <a href="https://github.com/aghattikar82/devops_bits_bytes/blob/main/Docker.md">Gituhub</a></li><li>Commands : <a href="https://github.com/aghattikar82/devops_bits_bytes/blob/main/Docker-commands">Docker Commands</a></li><li>Docker Interview Question : <a href="https://github.com/aghattikar82/devops_bits_bytes/blob/main/Docker-Interview-Question">Interview Question</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83d822e53cd8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Devop’s Bits & Bytes by Anup Ghattikar]]></title>
            <link>https://medium.com/@aghattikar82/devops-bits-bytes-by-anup-ghattikar-9a8c6b788ec9?source=rss-f9bc72cf44af------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a8c6b788ec9</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[devops-practice]]></category>
            <category><![CDATA[devops-tool]]></category>
            <category><![CDATA[tools]]></category>
            <dc:creator><![CDATA[Anup Ghattikar]]></dc:creator>
            <pubDate>Sun, 20 Aug 2023 13:33:01 GMT</pubDate>
            <atom:updated>2023-08-20T13:40:35.358Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Devop’s Bits &amp; Byte’s" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>Subscribe on LinkedIn</p><p><a href="https://www.linkedin.com/build-relation/newsletter-follow?entityUrn=7098718378797776896">https://www.linkedin.com/build-relation/newsletter-follow?entityUrn=7098718378797776896</a></p><p>Prepare for an Incredible DevOps Adventure with Anup Gattikar!</p><p>Prepare to immerse yourself in the world of DevOps like never before! Introducing “DevOps Bits and Bytes with Anup Gattikar” — your ultimate guide to mastering every aspect of DevOps.</p><p>Over the upcoming 50 weeks, we’re thrilled to present an incredible series of articles covering 50 DevOps topics. Each article is carefully crafted to empower you with comprehensive knowledge. From fundamental tools to cutting-edge techniques, we’ve got your learning journey covered!</p><p>Unleash the potential of CI/CD pipelines, delve into the enchantment of containerization, unlock the mysteries of infrastructure as code, and much more!</p><p>Join us on this transformative adventure as we demystify intricate concepts, provide real-world examples, and guide you through a variety of topics. Whether you’re an experienced professional or just stepping into the universe of DevOps, there’s something valuable for everyone.</p><p>Don’t miss the chance to enhance your DevOps proficiency. Stay tuned for regular updates every week, and let’s collaborate to shape a brighter, more efficient future in the realm of DevOps!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PaoLZAw1xX0TcEJ9sOTMng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qO5loI-_ROc3LH8JdLYaNw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xfufRzfDCqq51Ow4pgUfDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BgI9eBxq6hhQMjwFzs8eGw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LmVwCmlvTFrVkvoBaI9qCQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jMhXyaOTjy1ojH8tpgDmMw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aIKnNsJYUCbLINEUyGN62g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a8c6b788ec9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 6 Bash Scripting Challenge: The Mysterious Script]]></title>
            <link>https://medium.com/@aghattikar82/day-6-bash-scripting-challenge-the-mysterious-script-708c5a0ae6dc?source=rss-f9bc72cf44af------2</link>
            <guid isPermaLink="false">https://medium.com/p/708c5a0ae6dc</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[shell-script]]></category>
            <category><![CDATA[bash-script]]></category>
            <dc:creator><![CDATA[Anup Ghattikar]]></dc:creator>
            <pubDate>Thu, 10 Aug 2023 12:31:48 GMT</pubDate>
            <atom:updated>2023-08-10T12:31:48.712Z</atom:updated>
            <content:encoded><![CDATA[<p><strong># Day 6 Bash Scripting Challenge: The Mysterious Script</strong></p><p><strong>## Introduction</strong></p><p>Welcome to Day 6 of the 7-day Bash scripting challenge! In this challenge, you will encounter a mysterious Bash script named <a href="http://mystery.sh/">mystery.sh</a>. The script lacks documentation and comments, leaving its purpose and functionality shrouded in mystery. Your mission is to unravel the secrets of this script, understand its objective, and improve it by adding comments and explanations.</p><p><strong>## Challenge Steps</strong></p><p><strong>### Explore the Script</strong></p><p>Begin by examining the contents of <a href="http://mystery.sh/">mystery.sh</a>. The script contains various Bash commands, functions, or variables without any comments or explanations. Make note of any patterns or interesting code segments that might give you hints about the script&#39;s purpose.</p><p><strong>### Run the Script</strong></p><p>Execute <a href="http://mystery.sh/">mystery.sh</a> using the command bash <a href="http://mystery.sh/">mystery.sh</a> and observe its behavior. Pay attention to any output or changes in the system that might occur during the script&#39;s execution.</p><p><strong>### Debugging and Decoding</strong></p><p>Identify and fix any potential errors or bugs in the script that may prevent it from running correctly. Analyze the logic of the script to understand how it processes data or performs operations.</p><p><strong>### Identify the Objective</strong></p><p>Based on your observations and analysis, determine the main objective of the script. What is it trying to accomplish? Try to reverse-engineer the script’s logic to understand its intended purpose.</p><p><strong>### Add Comments and Explanation</strong></p><p>Now that you have a good understanding of the script’s purpose, modify <a href="http://mystery.sh/">mystery.sh</a> to add clear and concise comments at crucial points in the code. Explain the logic behind each major operation and any critical decisions made during the script&#39;s execution.</p><p><strong>### Optimize (Optional)</strong></p><p>If you think there are opportunities to optimize the script’s performance or make it more efficient, you can implement those changes. However, this step is entirely optional</p><p><strong>### Present Your Findings</strong></p><p>Document your journey of unraveling the mysterious script, explaining the steps you took to understand it and any challenges you encountered. Showcase the modified <a href="http://mystery.sh/">mystery.sh</a> script with added comments and explanations.</p><p><strong>Solution:</strong></p><pre># Function to Decrypt and Reverse Content</pre><pre>mysterious_function() {</pre><pre>local input_file=&quot;$1&quot;</pre><pre>local output_file=&quot;$2&quot;</pre><p><strong>#!/bin/bash</strong></p><p><strong># The Mysterious Script — Solution</strong></p><p><strong># This script takes an input file, applies a series of mysterious transformations, and saves the result in an output file.</strong></p><p><strong># Step 1: Decrypt the input file (ROT13 decryption)</strong></p><pre>tr &#39;A-Za-z&#39; &#39;N-ZA-Mn-za-m&#39; &lt; &quot;$input_file&quot; &gt; &quot;$output_file&quot;</pre><p><strong># Step 2: Reverse the content of the output file</strong></p><pre>rev &quot;$output_file&quot; &gt; &quot;reversed_temp.txt&quot;</pre><p><strong># Step 3: Generate a random number between 1 and 10</strong></p><pre>random_number=$(( ( RANDOM % 10 ) + 1 ))</pre><p><strong># Step 4: Mystery loop — Reverse and Encrypt the content multiple times</strong></p><pre>for (( i=0; i&lt;$random_number; i++ )); do</pre><p><strong># Reverse the output file again</strong></p><pre>rev &quot;reversed_temp.txt&quot; &gt; &quot;temp_rev.txt&quot;</pre><p><strong># Encrypt the reversed content (ROT13 encryption)</strong></p><pre>tr &#39;A-Za-z&#39; &#39;N-ZA-Mn-za-m&#39; &lt; &quot;temp_rev.txt&quot; &gt; &quot;temp_enc.txt&quot;</pre><p><strong># Swap the temporary files</strong></p><pre>mv &quot;temp_enc.txt&quot; &quot;reversed_temp.txt&quot;</pre><pre>done</pre><p><strong># Step 5: Clean up temporary files</strong></p><pre>rm &quot;temp_rev.txt&quot;</pre><pre>}</pre><p><strong># Main Script Execution</strong></p><p><strong># Check if two arguments are provided</strong></p><pre>if [ $# -ne 2 ]; then</pre><pre>echo &quot;Usage: $0 &lt;input_file&gt; &lt;output_file&gt;&quot;</pre><pre>exit 1</pre><pre>fi<br></pre><pre>input_file=&quot;$1&quot;</pre><pre>output_file=&quot;$2&quot;</pre><p><strong># Check if the input file exists</strong></p><pre>if [ ! -f &quot;$input_file&quot; ]; then</pre><pre>echo &quot;Error: Input file not found!&quot;</pre><pre>exit 1</pre><pre>fi</pre><p><strong># Call the mysterious function to begin the process</strong></p><pre>mysterious_function &quot;$input_file&quot; &quot;$output_file&quot;</pre><p><strong># Display the completion message</strong></p><pre>echo &quot;The mysterious process is complete. Check the &#39;$output_file&#39; for the result!&quot;</pre><p><strong># The Hungry Bash — Restaurant Order System Challenge</strong></p><p>Welcome to “<strong>The Hungry Bash</strong>” challenge!</p><p><strong>## Challenge Description</strong></p><p>In this challenge, you will be working on a Bash-based restaurant order system. The provided script, restaurant_order.sh, is partially broken and missing some crucial parts. Your task is to fix and complete the script to create a fully functional restaurant order system.</p><p><strong>### The Broken Script</strong></p><p>The restaurant_order.sh script is provided to you, but some essential parts are missing or not functioning correctly. Here are the broken parts:</p><p>1. <strong>Missing Menu Display</strong>: The script is missing the code to read and display the menu from the menu.txt file. You need to implement the function to read the menu and display it to the customers.</p><p>2. <strong>Invalid User Input Handling</strong>: The script is not handling invalid user input, such as entering a non-existent item number or negative quantities. You need to implement error handling to prompt users for valid inputs when necessary</p><p>3. <strong>Total Bill Calculation</strong>: The script is not calculating the correct total bill based on the customer’s order. You need to implement the function to calculate the total bill accurately.</p><p><strong>#!/bin/bash</strong></p><p><strong># Function to read and display the menu from menu.txt file</strong></p><pre>function display_menu() {</pre><pre>echo &quot;Welcome to the Restaurant!&quot;</pre><pre>echo &quot;Menu:&quot;</pre><p><strong># Read the menu from menu.txt and display item numbers and prices</strong></p><pre>local item_number=1</pre><pre>while IFS= read -r line; do</pre><pre>name=&quot;$(echo &quot;$line&quot; | cut -d&#39;,&#39; -f1)&quot;</pre><pre>price=&quot;$(echo &quot;$line&quot; | cut -d&#39;,&#39; -f2)&quot;</pre><pre>echo &quot;$item_number. $name - ₹$price&quot;</pre><pre>((item_number++))</pre><pre>done &lt; &quot;menu.txt&quot;</pre><pre>}</pre><p><strong># Function to calculate the total bill</strong></p><pre>function calculate_total_bill() {</pre><pre>local total=0</pre><p><strong># Calculate the total bill based on the customer’s order</strong></p><pre>for item_number in &quot;${!order[@]}&quot;; do</pre><pre>price=$(sed -n &quot;${item_number}p&quot; &quot;menu.txt&quot; | cut -d&#39;,&#39; -f2)</pre><pre>quantity=&quot;${order[$item_number]}&quot;</pre><pre>((total += price * quantity))</pre><pre>done</pre><pre>echo &quot;$total&quot;</pre><pre>}</pre><p><strong># Function to handle invalid user input</strong></p><pre>function handle_invalid_input() {</pre><pre>echo &quot;Invalid input! Please enter a valid item number and quantity.&quot;</pre><pre>}</pre><p><strong># Main script</strong></p><pre>display_menu</pre><p><strong># Ask for the customer’s name</strong></p><pre>echo -n &quot;Please enter your name: &quot;</pre><pre>read customer_name</pre><p><strong># Ask for the order</strong></p><pre>echo &quot;Please enter the item number and quantity (e.g., 1 2 for two Burgers):&quot;</pre><pre>read -a input_order</pre><p><strong># Process the customer’s order</strong></p><pre>declare -A order</pre><pre>for (( i=0; i&lt;${#input_order[@]}; i+=2 )); do</pre><pre>item_number=&quot;${input_order[i]}&quot;</pre><pre>quantity=&quot;${input_order[i+1]}&quot;</pre><pre>if [[ $item_number =~ ^[0-9]+$ &amp;&amp; $quantity =~ ^[0-9]+$ ]]; then</pre><pre>order[&quot;$item_number&quot;]=&quot;$quantity&quot;</pre><pre>else</pre><pre>handle_invalid_input</pre><pre>exit 1</pre><pre>fi</pre><pre>done</pre><p><strong># Calculate the total bill</strong></p><pre>total_bill=$(calculate_total_bill)</pre><p><strong># Display the total bill with a personalized thank-you message</strong></p><pre>echo &quot;Thank you, $customer_name! Your total bill is ₹$total_bill.&quot;</pre><p><strong># Recursive Directory Search Challenge</strong></p><p><strong>## Description</strong></p><p>The “Recursive Directory Search” challenge is part of the day-6. In this challenge, participants are tasked with creating a Bash script that performs a recursive search for a specific file within a given directory and its subdirectories. The script provided for this challenge is not functioning correctly, and participants must fix and improve it to achieve the desired behavior.</p><p><strong>## Challenge Details</strong></p><p><strong>Objective:</strong> Your goal is to fix the provided Bash script, recursive_search.sh, and ensure it performs the recursive search as described below</p><p>- The script should take two command-line arguments: the directory to start the search and the target file name to find.</p><p>- The search should be recursive, meaning it should look for the target file not only in the specified directory but also in all its subdirectories and their subdirectories, and so on.</p><p>- When the target file is found, the script should print the absolute path of the file and then exit.</p><p>- Proper error handling should be in place to handle cases where the directory does not exist or the target file is not found.</p><p><strong>#!/bin/bash</strong></p><pre>if [ $# -ne 2 ]; then</pre><pre>echo &quot;Usage: ./recursive_search.sh &lt;directory&gt; &lt;target_file&gt;&quot;</pre><pre>exit 1</pre><pre>fi</pre><pre>search_directory=&quot;$1&quot;</pre><pre>target_file=&quot;$2&quot;</pre><p><strong># Function to perform recursive search for the target file</strong></p><pre>function search_recursive {</pre><pre>local current_dir=&quot;$1&quot;</pre><p><strong># Iterate through the contents of the current directory</strong></p><pre>for file in &quot;$current_dir&quot;/*; do</pre><pre>if [ -d &quot;$file&quot; ]; then</pre><p><strong># If the current item is a directory, call the function recursively with the subdirectory</strong></p><pre>search_recursive &quot;$file&quot;</pre><pre>elif [ -f &quot;$file&quot; ] &amp;&amp; [ &quot;$(basename &quot;$file&quot;)&quot; = &quot;$target_file&quot; ]; then</pre><p><strong># If the current item is a file and its name matches the target file, print its absolute path </strong>and exit</p><pre>echo &quot;File found: $file&quot;</pre><pre>exit 0</pre><pre>fi</pre><pre>done</pre><pre>}</pre><p><strong># Check if the provided directory exists</strong></p><pre>if [ ! -d &quot;$search_directory&quot; ]; then</pre><pre>echo &quot;Error: Directory &#39;$search_directory&#39; not found.&quot;</pre><pre>exit 1</pre><pre>fi</pre><p><strong># Start the recursive search by calling the search_recursive function with the provided search directory</strong></p><pre>search_recursive &quot;$search_directory&quot;</pre><p><strong># If the loop completes without finding the target file, display a “File not found” message and exit with an error</strong></p><pre>echo &quot;File not found: $target_file&quot;</pre><pre>exit 1</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=708c5a0ae6dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bash Scripting Challenge — Log Analyzer and Report Generator]]></title>
            <link>https://medium.com/@aghattikar82/bash-scripting-challenge-log-analyzer-and-report-generator-4b7d272bdfd0?source=rss-f9bc72cf44af------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b7d272bdfd0</guid>
            <category><![CDATA[shell-script]]></category>
            <category><![CDATA[bash-script]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Anup Ghattikar]]></dc:creator>
            <pubDate>Thu, 10 Aug 2023 00:31:57 GMT</pubDate>
            <atom:updated>2023-08-10T00:31:57.522Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Bash Scripting Challenge — Log Analyzer and Report Generator</strong></h3><p><strong># Day 5: Bash Scripting Challenge — Log Analyzer and Report Generator</strong></p><p><strong>## Challenge Title: Log Analyzer and Report Generator</strong></p><p><strong>## Scenario</strong></p><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><p><strong>## Task</strong></p><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><p>1. <strong>Input:</strong> The script should take the path to the log file as a command-line argument.</p><p><strong># Step 1: Count the total number of lines in the log file</strong></p><pre>total_lines=$(wc -l &lt; &quot;$log_file&quot;)</pre><p>2. <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><p><strong># Step 2: Count the number of error messages (identified by the keyword “ERROR” in this </strong>example)</p><pre>error_count=$(grep -c -i &quot;ERROR&quot; &quot;$log_file&quot;)</pre><p>3. <strong>Critical Events:</strong> Search for lines containing the keyword “CRITICAL” and print those lines along with the line number.</p><p><strong># Step 3: Search for critical events (lines containing the keyword “CRITICAL”) and store </strong>them in an array</p><pre>mapfile -t critical_events &lt; &lt;(grep -n -i &quot;CRITICAL&quot; &quot;$log_file&quot;)</pre><p>4. <strong>Top Error Messages:</strong> Identify the top 5 most common error messages and display them along with their occurrence count.</p><p><strong># Step 4: Identify the top 5 most common error messages and their occurrence count using associative arrays</strong></p><pre>declare -A error_messages</pre><pre>while IFS= read -r line; do</pre><p><strong># Use awk to extract the error message (fields are space-separated)</strong></p><pre>error_msg=$(awk &#39;{for (i=3; i&lt;=NF; i++) printf $i &quot; &quot;; print &quot;&quot;}&#39; &lt;&lt;&lt; &quot;$line&quot;)</pre><pre>((error_messages[&quot;$error_msg&quot;]++))</pre><pre>done &lt; &lt;(grep -i &quot;ERROR&quot; &quot;$log_file&quot;)</pre><p><strong># Sort the error messages by occurrence count (descending order)</strong></p><pre>sorted_error_messages=$(for key in &quot;${!error_messages[@]}&quot;; do</pre><pre>echo &quot;${error_messages[$key]} $key&quot;</pre><pre>done | sort -rn | head -n 5)</pre><p>5. <strong>Summary Report:</strong> Generate a summary report in a separate text file. The report should include:</p><p>- Date of analysis</p><p>- Log file name</p><p>- Total lines processed</p><p>- Total error count</p><p>- Top 5 error messages with their occurrence count</p><p>- List of critical events with line numbers</p><p><strong># Step 5: Generate the summary report in a separate file</strong></p><pre>summary_report=&quot;log_summary_$(date +%Y-%m-%d).txt&quot;</pre><pre>{</pre><pre>echo &quot;Date of analysis: $(date)&quot;</pre><pre>echo &quot;Log file: $log_file&quot;</pre><pre>echo &quot;Total lines processed: $total_lines&quot;</pre><pre>echo &quot;Total error count: $error_count&quot;</pre><pre>echo -e &quot;\nTop 5 error messages:&quot;</pre><pre>echo &quot;$sorted_error_messages&quot;</pre><pre>echo -e &quot;\nCritical events with line numbers:&quot;</pre><pre>for event in &quot;${critical_events[@]}&quot;; do</pre><pre>echo &quot;$event&quot;</pre><pre>done</pre><pre>} &gt; &quot;$summary_report&quot;<br></pre><pre>echo &quot;Summary report generated: $summary_report&quot;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b7d272bdfd0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BashBlaze Scripting Challenge — Process Monitoring and Management]]></title>
            <link>https://medium.com/@aghattikar82/bashblaze-scripting-challenge-process-monitoring-and-management-ffd642f15bb5?source=rss-f9bc72cf44af------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffd642f15bb5</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[shell-script]]></category>
            <category><![CDATA[bash-script]]></category>
            <dc:creator><![CDATA[Anup Ghattikar]]></dc:creator>
            <pubDate>Wed, 09 Aug 2023 13:33:55 GMT</pubDate>
            <atom:updated>2023-08-09T13:33:55.228Z</atom:updated>
            <content:encoded><![CDATA[<h3>BashBlaze Scripting Challenge — Process Monitoring and Management</h3><p><strong># BashBlaze Scripting Challenge — Day 4</strong></p><p>Welcome to the Bash Scripting Challenge — Day 4! This challenge is designed to test your Bash scripting skills and problem-solving abilities in the context of process monitoring and management.</p><p><strong>## Task</strong></p><p>1. <strong>Process Selection:</strong></p><p>- The script should accept a command-line argument to specify the target process to monitor. For example: ./monitor_process.sh &lt;process_name&gt;.</p><p>2. <strong>Process Existence Check:</strong></p><p>- Implement a function that checks if the specified process is currently running on the system.</p><p>- If the process is running, print a message indicating its presence.</p><p>3. <strong>Restarting the Process:</strong></p><p>- If the process is not running, implement a function that attempts to restart the process automatically.</p><p>- Print a message indicating the attempt to restart the process.</p><p>- Ensure the script does not enter an infinite loop while restarting the process. Limit the number of restart attempts.</p><p>4. <strong>Automation:</strong></p><p>- Provide instructions on how to schedule the script to run at regular intervals using a cron job or any other appropriate scheduling method</p><p><strong>Solution:</strong></p><p><strong>#!/bin/bash</strong></p><p><strong># Function to check if the specified process is running</strong></p><pre>is_process_running() {</pre><pre>if pgrep -x &quot;$1&quot; &gt;/dev/null; then</pre><pre>return 0</pre><pre>else</pre><pre>return 1</pre><pre>fi</pre><pre>}</pre><p><strong># Function to restart the process using systemctl</strong></p><pre>restart_process() {</pre><pre>local process_name=&quot;$1&quot;</pre><pre>echo &quot;Process $process_name is not running. Attempting to restart...&quot;</pre><p><strong># Check if the user has the privilege to restart the process</strong></p><pre>if sudo systemctl restart &quot;$process_name&quot;; then</pre><pre>echo &quot;Process $process_name restarted successfully.&quot;</pre><pre>else</pre><pre>echo &quot;Failed to restart $process_name. Please check the process manually.&quot;</pre><pre>fi</pre><pre>}</pre><p><strong># Check if a process name is provided as an argument</strong></p><pre>if [ $# -eq 0 ]; then</pre><pre>echo &quot;Usage: $0 &lt;process_name&gt;&quot;</pre><pre>exit 1</pre><pre>fi<br></pre><pre>process_name=&quot;$1&quot;</pre><pre>max_attempts=3</pre><pre>attempt=1</pre><p><strong># Loop to check and restart the process</strong></p><p><strong># Monitoring Metrics Script with Sleep Mechanism</strong></p><pre>while [ $attempt -le $max_attempts ]; do<br>if is_process_running &quot;$process_name&quot;; then<br>echo &quot;Process $process_name is running.&quot;<br>else<br>restart_process &quot;$process_name&quot;<br>fi<br>attempt=$((attempt + 1))<br>sleep 5 # Wait for 5 seconds before the next check<br>done<br>echo &quot;Maximum restart attempts reached. Please check the process manually.&quot;</pre><p><strong>## Challenge Description</strong></p><p>This project aims to create a Bash script that monitors system metrics like CPU usage, memory usage, and disk space usage. The script will provide a user-friendly interface, allow continuous monitoring with a specified sleep interval, and extend its capabilities to monitor specific services like Nginx.</p><p><strong>## Tasks</strong></p><p><strong>### Task 1: Implementing Basic Metrics Monitoring</strong></p><p>Write a Bash script that monitors the CPU usage, memory usage, and disk space usage of the system. The script should display these metrics in a clear and organized manner, allowing users to interpret the data easily. The script should use the top, free, and df commands to fetch the metrics.</p><p><strong>### Task 2: User-Friendly Interface</strong></p><p>Enhance the script by providing a user-friendly interface that allows users to interact with the script through the terminal. Display a simple menu with options to view the metrics and an option to exit the script.</p><p><strong>### Task 3: Continuous Monitoring with Sleep</strong></p><p>Introduce a loop in the script to allow continuous monitoring until the user chooses to exit. After displaying the metrics, add a “sleep” mechanism to pause the monitoring for a specified interval before displaying the metrics again. Allow the user to specify the sleep interval.</p><p><strong>### Task 4: Monitoring a Specific Service (e.g., Nginx)</strong></p><p>Extend the script to monitor a specific service like Nginx. Check if the service is running and display its status. If it is not running, provide an option for the user to start the service. Use the systemctl or appropriate command to check and control the service.</p><p><strong>### Task 5: Allow User to Choose a Different Service</strong></p><p>Modify the script to give the user the option to monitor a different service of their choice. Prompt the user to enter the name of the service they want to monitor, and display its status accordingly.</p><p><strong>### Task 6: Error Handling</strong></p><p>Implement error handling in the script to handle scenarios where commands fail or inputs are invalid. Display meaningful error messages to guide users on what went wrong and how to fix it.</p><p><strong>Solutions:</strong></p><p><strong>#!/bin/bash</strong></p><p><strong># Function to display system metrics (CPU, memory, disk space)</strong></p><pre>function view_system_metrics() {</pre><pre>echo &quot;---- System Metrics ----&quot;</pre><p><strong># Fetch CPU usage using </strong>top<strong> command and extract the value using awk</strong></p><pre>cpu_usage=$(top -bn 1 | grep &#39;%Cpu&#39; | awk &#39;{print $2}&#39;)</pre><p><strong># Fetch memory usage using </strong>free<strong> command and extract the value using awk</strong></p><pre>mem_usage=$(free | grep Mem | awk &#39;{printf(&quot;%.1f&quot;, $3/$2 * 100)}&#39;)</pre><p><strong># Fetch disk space usage using </strong>df<strong> command and extract the value using awk</strong></p><pre>disk_usage=$(df -h / | tail -1 | awk &#39;{print $5}&#39;)</pre><pre>echo &quot;CPU Usage: $cpu_usage% Mem Usage: $mem_usage% Disk Space: $disk_usage&quot;</pre><pre>}</pre><p><strong># Function to monitor a specific service</strong></p><pre>function monitor_service() {</pre><pre>echo &quot;---- Monitor a Specific Service ----&quot;</pre><pre>read -p &quot;Enter the name of the service to monitor: &quot; service_name</pre><p><strong># Check if the service is running using </strong>systemctl<strong> command</strong></p><pre>if systemctl is-active --quiet $service_name; then</pre><pre>echo &quot;$service_name is running.&quot;</pre><pre>else</pre><pre>echo &quot;$service_name is not running.&quot;</pre><pre>read -p &quot;Do you want to start $service_name? (Y/N): &quot; choice</pre><pre>if [ &quot;$choice&quot; = &quot;Y&quot; ] || [ &quot;$choice&quot; = &quot;y&quot; ]; then</pre><p><strong># Start the service using </strong>systemctl<strong> command</strong></p><pre>systemctl start $service_name</pre><pre>echo &quot;$service_name started successfully.&quot;</pre><pre>fi</pre><pre>fi</pre><pre>}</pre><p><strong># Main loop for continuous monitoring</strong></p><pre>while true; do</pre><pre>echo &quot;---- Monitoring Metrics Script ----&quot;</pre><pre>echo &quot;1. View System Metrics&quot;</pre><pre>echo &quot;2. Monitor a Specific Service&quot;</pre><pre>echo &quot;3. Exit&quot;<br></pre><pre>read -p &quot;Enter your choice (1, 2, or 3): &quot; choice<br></pre><pre>case $choice in</pre><pre>1)</pre><pre>view_system_metrics</pre><pre>;;</pre><pre>2)</pre><pre>monitor_service</pre><pre>;;</pre><pre>3)</pre><pre>echo &quot;Exiting the script. Goodbye!&quot;</pre><pre>exit 0</pre><pre>;;</pre><pre>*)</pre><pre>echo &quot;Error: Invalid option. Please choose a valid option (1, 2, or 3).&quot;</pre><pre>;;</pre><pre>esac<br></pre><pre># Sleep for 5 seconds before displaying the menu again</pre><pre>sleep 5</pre><pre>done</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffd642f15bb5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 3 Bash Scripting Challenge — User Account Management]]></title>
            <link>https://medium.com/@aghattikar82/day-3-bash-scripting-challenge-user-account-management-9198c60035d3?source=rss-f9bc72cf44af------2</link>
            <guid isPermaLink="false">https://medium.com/p/9198c60035d3</guid>
            <category><![CDATA[shell-script]]></category>
            <category><![CDATA[bash-script]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Anup Ghattikar]]></dc:creator>
            <pubDate>Wed, 09 Aug 2023 13:15:32 GMT</pubDate>
            <atom:updated>2023-08-09T13:15:32.840Z</atom:updated>
            <content:encoded><![CDATA[<h3>Day 3 Bash Scripting Challenge — User Account Management</h3><p><strong>## Challenge: User Account Management</strong></p><p>In this challenge, you will create a bash script that provides options for managing user accounts on the system. The script should allow users to perform various user account-related tasks based on command-line arguments.</p><p><strong>### Part 1: Account Creation</strong></p><p>1. Implement an option -c or --create that allows the script to create a new user account. The script should prompt the user to enter the new username and password.</p><p>2. Ensure that the script checks whether the username is available before creating the account. If the username already exists, display an appropriate message and exit gracefully.</p><p>3. After creating the account, display a success message with the newly created username.</p><p><strong>Solution:</strong></p><p><strong>Function to create a new user account</strong></p><pre>function create_user {</pre><pre>read -p &quot;Enter the new username: &quot; username</pre><p><strong>Check if the username already exists</strong></p><pre>if id &quot;$username&quot; &amp;&gt;/dev/null; then</pre><pre>echo &quot;Error: The username &#39;$username&#39; already exists. Please choose a different username.&quot;</pre><pre>else</pre><p><strong>Prompt for password (Note: You might want to use ‘read -s’ to hide the password input)</strong></p><pre>read -p &quot;Enter the password for $username: &quot; password</pre><p><strong>Create the user account</strong></p><pre>useradd -m -p &quot;$password&quot; &quot;$username&quot;<br>echo &quot;User account &#39;$username&#39; created successfully.&quot;<br>fi<br>}</pre><p><strong>### Part 2: Account Deletion</strong></p><p>1. Implement an option -d or --delete that allows the script to delete an existing user account. The script should prompt the user to enter the username of the account to be deleted.</p><p>2. Ensure that the script checks whether the username exists before attempting to delete the account. If the username does not exist, display an appropriate message and exit gracefully.</p><p>3. After successfully deleting the account, display a confirmation message with the deleted username.</p><p><strong>Solution:</strong></p><pre># Function to delete an existing user account</pre><pre>function delete_user {</pre><pre>read -p &quot;Enter the username to delete: &quot; username</pre><p><strong># Check if the username exists</strong></p><pre>if id &quot;$username&quot; &amp;&gt;/dev/null; then</pre><pre>userdel -r &quot;$username&quot; # -r flag removes the user&#39;s home directory</pre><pre>echo &quot;User account &#39;$username&#39; deleted successfully.&quot;</pre><pre>else</pre><pre>echo &quot;Error: The username &#39;$username&#39; does not exist. Please enter a valid username.&quot;</pre><pre>fi</pre><pre>}</pre><p><strong>### Part 3: Password Reset</strong></p><p>1. Implement an option -r or --reset that allows the script to reset the password of an existing user account. The script should prompt the user to enter the username and the new password.</p><p>2. Ensure that the script checks whether the username exists before attempting to reset the password. If the username does not exist, display an appropriate message and exit gracefully.</p><p>3. After resetting the password, display a success message with the username and the updated password.</p><p><strong>Solution:</strong></p><pre># Function to reset the password for an existing user account</pre><pre>function reset_password {</pre><pre>read -p &quot;Enter the username to reset password: &quot; username</pre><p><strong># Check if the username exists</strong></p><pre>if id &quot;$username&quot; &amp;&gt;/dev/null; then</pre><pre># Prompt for password (Note: You might want to use &#39;read -s&#39; to hide the password input)</pre><pre>read -p &quot;Enter the new password for $username: &quot; password</pre><p><strong># Set the new password</strong></p><pre>echo &quot;$username:$password&quot; | chpasswd</pre><pre>echo &quot;Password for user &#39;$username&#39; reset successfully.&quot;</pre><pre>else</pre><pre>echo &quot;Error: The username &#39;$username&#39; does not exist. Please enter a valid username.&quot;</pre><pre>fi</pre><pre>}</pre><p><strong>### Part 4: List User Accounts</strong></p><p>1. Implement an option -l or --list that allows the script to list all user accounts on the system. The script should display the usernames and their corresponding user IDs (UID).</p><p><strong>Solution:</strong></p><pre># Function to list all user accounts on the system</pre><pre>function list_users {</pre><pre>echo &quot;User accounts on the system:&quot;</pre><pre>cat /etc/passwd | awk -F: &#39;{ print &quot;- &quot; $1 &quot; (UID: &quot; $3 &quot;)&quot; }&#39;</pre><pre>}</pre><p><strong>### Part 5: Help and Usage Information</strong></p><p>1. Implement an option -h or --help that displays usage information and the available command-line options for the script.</p><p><strong>Solution:</strong></p><pre># Command-line argument parsing<br>while [ $# -gt 0 ]; do<br>case &quot;$1&quot; in<br>-c|--create)<br>create_user<br>;;<br>-d|--delete)<br>delete_user<br>;;<br>-r|--reset)<br>reset_password<br>;;<br>-l|--list)<br>list_users<br>;;<br>*)<br>echo &quot;Error: Invalid option &#39;$1&#39;. Use &#39;--help&#39; to see available options.&quot;<br>exit 1<br>;;<br>esac<br>shift<br>done</pre><p><strong>### Bonus Points (Optional)</strong></p><p>If you want to challenge yourself further, you can add additional features to the script, such as:</p><p>- Displaying more detailed information about user accounts (e.g., home directory, shell, etc.).</p><p>- Allowing the modification of user account properties (e.g., username, user ID, etc.).</p><p><strong>Solution:</strong></p><pre># Check if no arguments are provided or if the -h or --help option is given<br>if [ $# -eq 0 ] || [ &quot;$1&quot; = &quot;-h&quot; ] || [ &quot;$1&quot; = &quot;--help&quot; ]; then<br>display_usage<br>exit 0<br>fi</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9198c60035d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 2 Bash Scripting Challenge — Interactive File and Directory Explorer]]></title>
            <link>https://medium.com/@aghattikar82/day-2-bash-scripting-challenge-interactive-file-and-directory-explorer-2855b37df796?source=rss-f9bc72cf44af------2</link>
            <guid isPermaLink="false">https://medium.com/p/2855b37df796</guid>
            <category><![CDATA[bash-script]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[shellscripting]]></category>
            <dc:creator><![CDATA[Anup Ghattikar]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 17:31:55 GMT</pubDate>
            <atom:updated>2023-08-02T17:31:55.723Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Day 2 Bash Scripting Challenge</strong> — Interactive File and Directory Explorer</h3><p><strong>Day 2 Bash Scripting Challenge</strong> — Interactive File and Directory Explorer</p><p>Welcome to Day 2 of the Bash Scripting Challenge! In this challenge, you will create a bash script that serves as an interactive file and directory explorer. The script will allow you to explore the files and directories in the current path and provide a character counting feature for the user’s input.</p><p>###<strong> Part 1: File and Directory Exploration</strong></p><p>1. Upon execution without any command-line arguments, the script will display a welcome message and list all the files and directories in the current path.</p><p>2. For each file and directory, the script will print its name and size in human-readable format (e.g., KB, MB, GB). This information will be obtained using the `ls` command with appropriate options.</p><p>3. The list of files and directories will be displayed in a loop until the user decides to exit the explorer.</p><p>### <strong>Part 2: Character Counting</strong></p><p>1. After displaying the file and directory list, the script will prompt the user to enter a line of text.</p><p>2. The script will read the user’s input until an empty string is entered (i.e., the user presses Enter without any text).</p><p>3. For each line of text entered by the user, the script will count the number of characters in that line.</p><p>4. The character count for each line entered by the user will be displayed.</p><p><strong>Solution:</strong></p><pre>#!/bin/bash<br># Part 1: File and Directory Exploration<br>echo &quot;Welcome to the Interactive File and Directory Explorer!&quot;<br>while true; do<br># List all files and directories in the current path<br>echo &quot;Files and Directories in the Current Path:&quot;<br>ls -lh<br># Part 2: Character Counting<br>read -p &quot;Enter a line of text (Press Enter without text to exit): &quot; input<br># Exit if the user enters an empty string<br>if [ -z &quot;$input&quot; ]; then<br>echo &quot;Exiting the Interactive Explorer. Goodbye!&quot;<br>break<br>fi<br># Calculate and print the character count for the input line<br>char_count=$(echo -n &quot;$input&quot; | wc -m)<br>echo &quot;Character Count: $char_count&quot;<br>done</pre><p><strong>ANOTHER CHALLENGE</strong></p><p><strong># Directory Backup with Rotation</strong></p><p>This is another challenge for Day 2 of the Bash Scripting Challenge! In this challenge, you will create a bash script that performs a backup of a specified directory and implements a rotation mechanism to manage backups.</p><p><strong>## Challenge Description</strong></p><p>Your task is to 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.</p><p>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.</p><p>The script will create a timestamped backup folder inside the specified directory and copy all the files into it. It will also check for existing backup folders and remove the oldest backups to keep only the last 3 backups.</p><p><strong>Solution:</strong></p><pre>#!/bin/bash<br># Function to display usage information and available options<br>function display_usage {<br>echo &quot;Usage: $0 /path/to/source_directory&quot;<br>}<br># Check if a valid directory path is provided as a command-line argument<br>if [ $# -eq 0 ] || [ ! -d &quot;$1&quot; ]; then<br>echo &quot;Error: Please provide a valid directory path as a command-line argument.&quot;<br>display_usage<br>exit 1<br>fi<br># Directory path of the source directory to be backed up<br>source_dir=&quot;$1&quot;<br># Function to create a timestamped backup folder<br>function create_backup {<br>local timestamp=$(date &#39;+%Y-%m-%d_%H-%M-%S&#39;) # Get the current timestamp<br>local backup_dir=&quot;${source_dir}/backup_${timestamp}&quot;<br># Create the backup folder with the timestamped name<br>mkdir &quot;$backup_dir&quot;<br>echo &quot;Backup created successfully: $backup_dir&quot;<br>}<br># Function to perform the rotation and keep only the last 3 backups<br>function perform_rotation {<br>local backups=($(ls -t &quot;${source_dir}/backup_&quot;* 2&gt;/dev/null)) # List existing backups sorted by timestamp<br># Check if there are more than 3 backups<br>if [ &quot;${#backups[@]}&quot; -gt 3 ]; then<br>local backups_to_remove=&quot;${backups[@]:3}&quot; # Get backups beyond the last 3<br>rm -rf &quot;${backups_to_remove[@]}&quot; # Remove the oldest backups<br>fi<br>}<br># Main script logic<br>create_backup<br>perform_rotation</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2855b37df796" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BASH SCRIPTING BASICS]]></title>
            <link>https://medium.com/@aghattikar82/bash-scripting-basics-8924bbbf8794?source=rss-f9bc72cf44af------2</link>
            <guid isPermaLink="false">https://medium.com/p/8924bbbf8794</guid>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[scripting]]></category>
            <dc:creator><![CDATA[Anup Ghattikar]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 09:37:01 GMT</pubDate>
            <atom:updated>2023-08-02T16:45:55.478Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*0c8srk9zBd79wC7a52GqQw.png" /></figure><p>Welcome to Day 1 of the Bash Scripting Challenge! Today, we will cover the basics of bash scripting to get you started. Let’s dive in:</p><h3>Task 1: Comments</h3><p>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.</p><p><strong>Solutions:</strong></p><p><strong>Ex:</strong></p><pre>#!/usr/bin/env bash<br> <br># Say hello to the community<br>echo &quot;Hello TWS Community!&quot;</pre><h3>Task 2: Echo</h3><p>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.</p><p><strong>Solutions:</strong></p><p><strong>Ex</strong>:</p><pre>echo &quot;Your current working directory is:&quot;<br>pwd</pre><pre>echo &quot;These are the contents of this directory:&quot;<br>ls -l</pre><h3>Task 3: Variables</h3><p>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.</p><p><strong>Solutions</strong></p><p><strong>Ex:</strong></p><pre># Variables<br>val1=&quot;Hello&quot;<br>val2=&quot;TWS Cummunity&quot;</pre><h3>Task 4: Using Variables</h3><p>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.</p><p><strong>Solutions</strong></p><p><strong>Ex:</strong></p><pre># Using Variables<br>print=&quot;$val1,$val2!&quot;<br>echo &quot;$print Welcome to the SHELL SCRIPTING CHALLENAGE&quot;</pre><h3>Task 5: Using Built-in Variables</h3><p>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.</p><p><strong>Solutions</strong></p><p><strong>Ex:</strong></p><pre># Using Built-in Variables<br>echo &quot;My current bash path - $BASH&quot;<br>echo &quot;Bash version I am using - $BASH_VERSION&quot;<br>echo &quot;PID of bash I am running - $$&quot;<br>echo &quot;My home directory - $HOME&quot;<br>echo &quot;Where am I currently? - $PWD&quot;<br>echo &quot;My hostname - $HOSTNAME&quot;</pre><h3>Task 6: Wildcards</h3><p>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.</p><p><strong>Solutions</strong></p><p><strong>Ex:</strong></p><pre>echo &quot;Files with .txt extension in the current directory:&quot;<br>ls *.txt<br><br># Prompt the user to enter the directory path<br>read -p &quot;Enter the directory path: &quot; directory_path<br><br># Prompt the user to enter the file extension<br>read -p &quot;Enter the file extension (e.g., txt, jpg, etc.): &quot; file_extension<br><br># List all files with the specified extension in the given directory<br>echo &quot;Files with the .$file_extension extension in $directory_path:&quot;<br><br>ls &quot;$directory_path&quot;/*.&quot;$file_extension&quot;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8924bbbf8794" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DAY 12 Completed #Completed #90daysofdevops]]></title>
            <link>https://medium.com/@aghattikar82/day-12-completed-completed-90daysofdevops-c251db911289?source=rss-f9bc72cf44af------2</link>
            <guid isPermaLink="false">https://medium.com/p/c251db911289</guid>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Anup Ghattikar]]></dc:creator>
            <pubDate>Wed, 01 Mar 2023 23:20:45 GMT</pubDate>
            <atom:updated>2023-03-01T23:20:45.632Z</atom:updated>
            <content:encoded><![CDATA[<p>DAY 12 Completed #Completed #90daysofdevops</p><p>https://www.linkedin.com/posts/aghattikar82_linux-command-and-github-cheet-sheet-activity-7024134307594084352-aFB7?utm_source=share&amp;utm_medium=member_android</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c251db911289" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>