Posts

Showing posts with the label Bash Scripting

Bash Scripting Series — Level 4

Bash Scripting Series — Level 4: Checking Running Processes and Finding PIDs Introduction In Level 3, we created a Bash script that validates a directory and generates a compressed backup. We used conditional statements, loops, variables, and exit-status handling to make the script more reliable. In Level 4, we move from filesystem operations to process management . Linux runs many processes simultaneously. These include system services, terminal commands, background jobs, applications, and security tools. Sometimes, you need to determine whether a particular process is running and identify its Process ID (PID). For example, you might want to check whether a monitoring tool is running, verify that a background task started successfully, or locate a process for troubleshooting. In this lesson, we will examine a Bash script that searches for a process by name, displays its PID or PIDs, and reports when no matching process is found. 1. The Original Script Here is the script we will analyz...

Bash Scripting Series — Level 3

  Bash Scripting Series — Level 3: Creating Automated Directory Backups Introduction In Level 2, we learned how to validate user input and check whether a directory exists. Now, we will combine those concepts to create a practical backup script. Backups are an essential part of system administration. They help preserve files before system changes, support recovery after accidental deletion, and provide copies of important data. In this lesson, we will create a Bash script that asks the user for a directory, validates the path, creates a backup directory, generates a timestamp, and compresses the selected directory into a .tar.gz archive. We will also identify a few issues in the original script and improve its error handling. 1. The Original Script #!/bin/bash # TODO: Prompt the user to enter a directory path read -p "Enter a directory path to continue: " dir # TODO: Check if the user provided input if [ -z "$dir" ]; then echo "No directory path provided...

Bash Scripting Series — Level 2

  Bash Scripting Series — Level 2: Directory Validation and Conditional Statements Introduction In Level 1, we explored the Linux command line and learned how to navigate the filesystem and execute basic commands. In Level 2, we begin writing scripts that make decisions based on specific conditions. Consider a script that saves security scan results to a directory. Before saving anything, it should verify that the destination exists. This helps prevent avoidable errors and makes the script more reliable. In this lesson, we will build a directory validation script and explore the Bash concepts behind it, how to run and test it, and how to expand it into a more useful tool. 1. The Original Script #!/bin/bash # Ask the user for a directory path read -p "Enter a directory path: " dir # Check whether input was provided if [ -z "$dir" ]; then echo "Error: No directory path provided." exit 1 fi # Check whether the directory exists if [ -d "$dir...

Installing Ubuntu on VirtualBox

Installing Ubuntu on VirtualBox: A Beginner’s Guide Introduction Before starting the Bash scripting series, you need a Linux environment where you can practice commands, write scripts, and experiment safely. One of the easiest ways to get started is to install Ubuntu inside a virtual machine using Oracle VirtualBox. In this tutorial, we will walk through downloading Ubuntu, installing VirtualBox, creating a virtual machine, and completing the initial Ubuntu setup. You do not need to replace Windows or repartition your computer's physical drive. Ubuntu will run inside a virtual machine, allowing you to learn Linux while keeping your existing operating system. What You Will Need A Windows, macOS, or Linux computer. Oracle VirtualBox installed on your computer. The Ubuntu Desktop ISO installation file. Enough free disk space and memory for a virtual machine. Estimated time: 30–60 minutes, depending on your computer and internet connection. Table of Contents Introduction to Ubuntu In...

Linux 101

  Linux 101: Essential Prerequisites for the Bash Scripting Series Before jumping into Bash scripting, it is important to understand the environment in which your scripts will run. Bash is a command-line shell used on Linux systems, and learning to work with Linux will make writing, testing, and troubleshooting scripts much easier. This guide covers the essential Linux fundamentals you should understand before starting the Bash scripting series. We will explore the Linux command line, file-system navigation, file management, text editors, package management, users, and file permissions. You do not need to be a Linux expert before getting started. The goal is to become comfortable using the terminal and understanding the commands you will encounter throughout the series. What You Will Learn By the end of this guide, you should be familiar with: Linux distributions and how to set up a Linux environment. The Bash shell and basic command structure. Identifying system information and CP...

Bash Scripting Series — Level 1

  Bash Scripting for Beginners — Level 1: Linux Command-Line Foundations Series: Bash Scripting for Beginners Level: 1 — Beginner Environment: Ubuntu Terminal Focus: File listing, navigation, copying, permissions, searching, and user management Introduction Welcome to Level 1 of this Bash scripting series! Before writing scripts that automate tasks, you need to understand how to interact with Linux through the command line. The terminal allows you to navigate directories, inspect files, manage permissions, search the filesystem, and administer user accounts. These skills are especially useful in cybersecurity, where you may need to investigate files, inspect permissions, manage Linux systems, or automate repetitive tasks. In this lesson, we'll work through seven practical exercises using Ubuntu. What you'll learn By the end of this lesson, you should be able to: List files and inspect their permissions. Navigate a directory structure using relative paths. Copy files using c...