diff --git a/2026/day-01/learning-plan.md b/2026/day-01/learning-plan.md new file mode 100644 index 0000000000..a80ec91be6 --- /dev/null +++ b/2026/day-01/learning-plan.md @@ -0,0 +1,4 @@ +# Plan for 90 days +Linux basics -2 weeks +Git/Github - 1 week +Docker - 1 week diff --git a/2026/day-02/linux-architecture-notes.md b/2026/day-02/linux-architecture-notes.md new file mode 100644 index 0000000000..b17bbad5f5 --- /dev/null +++ b/2026/day-02/linux-architecture-notes.md @@ -0,0 +1,24 @@ +# Devops Commad and systemd +A - Application/user
+S - Shell (terminal where you access shell)
+K - Kernel
+ +BIOS runs Hardware ---> GNU GRUB load linux kernel ---> ubuntu loading --> init process/systemd
+ +File System: / --root
+ / > ls ---you get bin sbin called directories binaries and systembinaries
+ /user/bin > ls --shows all the linux command
+ /user/you dir name -- make directory inside home and work here
+ +Everything start with process
+Command: uname -r ----Gives version of op system Kernel free ---shows memory
+ htop/top ---- all the process running ip addr --gives ip address
+ ps aux | grep ping ----SS of running process systemctl start nginx/docker/python/ssh
+ ping XXXX.com ---gives all the ip of ping Api of website systemctl status docker/ssh
+ man (ex. man ls) ----manuel for all the command
+ touch hello.txt --to make file
+ mkdir ---to make directory
+ ls -l --detail of file | ls cp in bin will show availablity
+ cp -r file1(source) file2(destination) --copy folder/files
+ mv file1(source) file2(destination) --rename/move files
+ rmdir filename/ rm -r filename ---to remove directory(shift delete similar for rm command)
diff --git a/2026/day-03/linux-commands-cheatsheet.md b/2026/day-03/linux-commands-cheatsheet.md new file mode 100644 index 0000000000..b9cce1bf72 --- /dev/null +++ b/2026/day-03/linux-commands-cheatsheet.md @@ -0,0 +1,94 @@ +# Process Management +systemd is the 1st process
+systemctl status nginx/docker --to check status of process
+systemctl start nginx/docker --- To start any process
+systemctl stop nginx/docker --- To Stop any process
+journalctl -u nginx/docker ---- to show all logs of an individual process
+ +# User Management +whoami ---- shoes which user is active
+sudo adduser xxx --- Adds user and made directory automatically
+sudo passwd xxx --- set up password for login
+su xxx --- command to enter inside user giving password (opens black bash)
+which bash --- which bash currently am i using (usually coloured) gives path
+sudo useradd -m yyy -s usr/bin/bash --- to make bash similar to **older coloured style** and using -m (Simialr to windows switching)
+cd / > cd home --- ls -l gives list of all users
+cat /etc/group --- shows all the user group
+sudo addgroup ggg ---making group for user
+sudo gpasswd -a xxx ggg ---adding user inside group. here xxx is added in group ggg along **with permission** gets added
+sudo gpasswd -d xxx ggg ---To remove the user from that group and revoke their permissions. Restart with newgrp current user
+sudo usermod -aG docker ubuntu ---Adding an Ubuntu User to the docker Group to **avoid sudo** and have permissions
+sudo chown ggg filename.txt ---change the individual owner of the file from ubuntu to other user only valid for individual
+sudo chgrp xxx filename.txt --change group owner can be done with chown (:) as well
+# File System +Read (cat)
+Write (vim/nano)
+Execute (shell/ ./)
+mkdir -p devops -----makes directory **with path** without error even if it exists do not throw error
+vim hello.txt > Insert i > write content > Esc > :wq(save and quit)/:q!(exit without saving)
+newgrp ubuntu --- changes current active primary group to the group named ubuntu for your current terminal session
+-rwxrwxrwx --read write execute for **owner group others** in sets of 3
+chmod 777 ---giving all permission / chmod 400 ----giving only read permission
+ +# Volume Mounting +lsblk ---volume/disk all attached to the server shows block with various partition
+xvda ---extended version is written in form **/dev/xvda**
+df -h ---free disk space in disk and shows mount point
+Attach and Mount are 2 different thing. /dev/xvda shows attachment to system
+Instance attached to volume is called attaching. Binding volume to a location is called mounting.
+EBS(Elastic block store to to create ssd) ---go to EBS in aws and create multiple volumes.
+select volume > Actions > Attach volume to the corrosponding instances(select correct device name) > Check through lsblk
+To make volume of EBS into useable volume convert into Physical Volume
+Logical volume size can be incraesed or decreased according to the usage
+ + LVM(Logical Volume Manager) + ------------Logical Volume----------------------- + -------- --------- ---------- + | 10GB | | 6GB | | | + --------- ---------- ----------- + | | | + | | | + ------------------------------------------------------ + | Volume Group | + | | + ------------------------------------------------------- + | | | + | | | + -------- --------- ---------- + | 10G | | 12G | | 11 GB | + --------- ---------- ----------- + --------------Physical volume------------------- + +# Logical Volume Manager (LVM) +Sudo lvm ---become a root user initially. Its a tool to manage LVM having commands for mounting
+pvcreate /dev/xvdf /dev/xvdg /dev/xvdh ----create physical volume for 3 ebs volume available in aws
+pvs ---- shows the physical volume details
+ +vgcreate tws_vg /dev/xvdf /dev/xvdg ---To create Volume group using 2 physical volume earlier made. initail is the vg nam and then from the source path to be combined
+vgs ----shows list of all the volume from group craeted where PV is phy. vol. and LV is Logical vol.
+ +lvcreate -L 10G -n tws_lv tws_vg --- to create logical volume from the volumegroup
+lvs --- shows list of all the volume of group created
+ +pvdisplay ---- to display physical volume details
+vgdisplay ----- to display volume group details
+lvdisplay ---- to displaylogical volume details
+ +# How to mount volumes +Go to root always
+mkdir /mnt/tws_lv_mount --- create a temproary directory which creates a location where volume is mounted
+mkfs.ext4 /dev/tws_vg/tws_lv ---to format the path and create space and make file system
+mount /dev/tws_vg/tws_lv /mnt/tws_lv_mount --mount the logical volume to specified location craeted before to bind the path
+umount /mnt/tws_lv_mount ---to unmount the volume directory
+Now you can use the path to craete directory and work here /mnt/tws_lv_mount
+ +# Directly mount physical volume to disk mount +No need to go to room
+mkdir /mnt/tws_disk_mount ----this is to create space for disk mount directly from phy. vol.
+mkfs -t ext4 /dev/xvdh ----file system to mount disk store
+mount /dev/xvdh /mnt/tws_disk_mount --- mounting disk to the destination
+df -h --to check all the disk mounted
+ +# Dynamic storage management with EBS(AWS) +Adding extra storage to Logical Volume
+lvm > lvextend -L +5G -n /dev/tws_vg/tws_lv
diff --git a/2026/day-04/linux-practice.md b/2026/day-04/linux-practice.md new file mode 100644 index 0000000000..f8a8357559 --- /dev/null +++ b/2026/day-04/linux-practice.md @@ -0,0 +1,36 @@ +Systemctl status ssh/docker --- to see the curreent status of a single process
+image + +sudo systemctl start nginx/docker/ssh ----to stop the process
+image + +sudo systemctl stop nginx/docker/ssh ----to stop the process
+image + +ping zeiss.com ---Sends icmp packets to the hosts
+htop -- to see the running status of the process and track live running process
+image + +ps aux | grep zeiss --it create the screen shot of the process and grep filter the required process
+kill -9 PID --force kill the running process
+kill PID --kill the process
+image + +systemctl list-units ----command displays all currently loaded and active \(systemd\) units (like services, sockets, and mount points) in memory.
+systemctl list-units --state=failed
+systemctl list-units --state=waiting
+image + +journalctl -u docker/nginx/ssh --- to see all the log file of a sinle process
+image + +head -n 5 --- this is to see first 5 line in log files or any files
+image + +tail -n 5 --- this is to see last 5 line in log files or any files
+image + +# Process additional command +pstree ubuntu --- Visualizes running processes in a hierarchical, parent-child tree structure
+pgrep nginx --- Searches for processes by name and returns their Process IDs (PIDs)
+image diff --git a/2026/day-05/linux-troubleshooting-runbook.md b/2026/day-05/linux-troubleshooting-runbook.md new file mode 100644 index 0000000000..e5e798d09e --- /dev/null +++ b/2026/day-05/linux-troubleshooting-runbook.md @@ -0,0 +1,67 @@ +# Environment Basic +uname -a --give details aboutabout the Linux kernel and hardware architecture (What it outputs: Kernel version, kernel build date, CPU architecture)
+lsb_release -a (The Legacy Standard) --- prints all available Linux Standard Base (LSB) and **distribution-specific** version details
+cat /etc/os-release (The Modern Standard) --- tells you about the specific **Linux distribution** (OS) and its version
+image + +# filesystem sanity +mkdir /tmp/runbook-demo ---make directory
+cp /etc/hosts /tmp/runbook-demo/hosts-copy && ls -l /tmp/runbook-demo --copy directory file from hosts to copy hosts and dispalys permission
+image + +# Troubleshooting +systemctl status docker --- one target service/process to see the status
+image + +htop --to see the running process +image +image + + # customized details of CPU / Memory
+ps -o pid,pcpu,pmem,comm -p --- ps is process -o user-defined format pid - unique process id
+ pcpu --- details about cpu pmem --- detail about memory
+ comm --- short executable command -p --- specific process ID
+ free -h --- shows free space in human redeable format. without -h it is in byte format
+image + +# Disk / IO +df -h --detail of file system mounted
+du -sh /var/log --- calculates and displays the total disk space used by the /var/log folder in redeable format number
+iostat --- Focuses heavily on storage drive performance and input/output (I/O) speeds and idle time
+vmstat --- Focuses heavily on virtual memory, RAM, paging, processes, and CPU activity(Virtual Memory Statistics)
+dstat --- Combines both tools into a single, Everything simultaneously—CPU, disk, network, and memory(Versatile Statistics)
+image + +# Network +ss -tulpn -- display all open and listening network ports
+image + +netstat -tulpn --- displays same data but its old style
+image + +ping zeiss.com --checks network connectivity at the system level using ICMP (Is the server powered on and reachable?)
+curl -I API ---- checks application-layer web responses using HTTP(give full address) (Is the web application/API running and healthy?)
+image + +# Logfile +journalctl -u docker -n 5 ---shows the detail of any running process depending on number of lines asked (here 5 lines of docker)
+tail -n 5 /var/log/syslog --- last 5 lines of a particular log files
+image + +# If this worsens(example Nginx) +Nginx Troubleshooting ChecklistFollow this sequential checklist to diagnose, configure, and isolate web server failures
+Phase 1: Initial Triage & VerificationVerify OS Environment: Run cat /etc/os-release to confirm the distribution baseline.
+Test Network Reachability: Run ping to verify the physical server is online.
+Inspect HTTP Headers: Run curl -I http://localhost to capture the exact status code (e.g., 502 Bad Gateway).
+Audit Open Ports: Run sudo ss -tulpn to ensure Nginx is actively listening on ports 80/443. + +Phase 2: Elevate Verbosity (The "If This Worsens" Plan)
+Open Configuration: Run sudo nano /etc/nginx/nginx.conf (Do not use cd). +Enable Debug Logs: Locate the error_log directive and append debug to the end of the line:**nginxerror_log /var/log/nginx/error.log debug**
+Test Layout Syntax: sudo nginx -t ---- to verify there are no missing semicolons or typos.
+Apply Changes Safely: sudo systemctl reload nginx --- to load the settings without dropping user traffic.
+Stream Live Errors: sudo tail -f /var/log/nginx/error.log --- to watch the debug output in real time. + +Phase 3: Advanced Diagnostics & RecoveryTrace System Calls: Run sudo strace -fp -e trace=network,file on a worker PID if the process hangs.Isolate and Restart: If the state corrupts, run sudo systemctl stop nginx, confirm ports are vacant with ss, then run sudo systemctl start nginx. + + diff --git a/2026/day-06/file-io-practice.md b/2026/day-06/file-io-practice.md new file mode 100644 index 0000000000..d73cb5fdd2 --- /dev/null +++ b/2026/day-06/file-io-practice.md @@ -0,0 +1,15 @@ +# Operation in files +touch notes.txt ---- creates file with name notes
+echo "Line 1" > notes.txt -----add content to the line and over write if anything written
+echo "Line 2" >> notes.txt ----add content and append the content at the end it do not overwrite
+echo "Line 3" | tee -a notes.txt ---display the content as well as append at last. If -a not there it will overwrite
+cat notes.txt ---displayes the overall output +head -n 2 notes.txt ---diaplays firat 2 line
+tail -n 2 notes.txt ---displays last 2 lines
+image + +# Negative scenarios of > and tee without -a will overwrite whole file +echo "Line 1" > notes.txt -----add content to the line and over write if anything written
+echo "Line 2" >> notes.txt ----add content and append the content at the end it do not overwrite
+echo "Line 3" | tee notes.txt ---display the content as well as append at last. If -a not there it will overwrite
+image diff --git a/2026/day-07/day-07-linux-fs-and-scenarios.md b/2026/day-07/day-07-linux-fs-and-scenarios.md new file mode 100644 index 0000000000..2f448bb571 --- /dev/null +++ b/2026/day-07/day-07-linux-fs-and-scenarios.md @@ -0,0 +1,49 @@ +# Linux File System Hierarchy +Symbol / --root consists of all folder. System starts from here
+ / > ls -l ---you get bin sbin called directories binaries and system binaries
+ /user/bin > ls --shows all the linux command
+ /bin --- Essential command binaries all the commands are either on bin and system command is in sbin
+ /user/ -- make directory inside home and work here
+ /opt --- Optional/third-party applications
+ + /var/log - **Log files** -- all log files and can open through vim
+ image + +du -sh /var/log/* 2>/dev/null -- du -sh --is disk space -sh flah is summerize and human readable the log file, *wildcard to trace all
+ -- 2>dev/null ---its a black hole where all eoor goes for example permission denied + + Find the largest log file in /var/log. Use of log file scenario +du -sh /var/log/* 2>/dev/null | sort -h | tail -n 5 --sort and gives result of last 5 files
+image + +Negative scenarios --- this is without blackhole(**2>/dev/null**)
+image + +Look at a config file in /etc --shows which host is aasigned
+cat /etc/hostname ---displays the unique network name assigned to your Linux system
+ +Check your home directory +ls -la ~ ---list aal hidden file but ~ is used to access home directory from anywhere + +# Scenario 1 + systemctl status myapp ----Check the status of myapp
+ systemctl is-enabled myapp --is system enabled
+ sudo journalid -u myapp -e --no-pager --check the log file in chronological order
+ sudo ss -tulpn -- Check other service (like Apache or Nginx) already grabbed the port myapp needs
+ + # Scenario 2 + htop --to see memory usage + ps aux --sort=-pcpu | head -n 5 -- (-pcpu) arrange in decending and apply head or remove minus and apply tail
+ + # Scenario 3 + systemctl status docker ---status of docker
+ journalctl -u docker -n 50 ---chek log file
+ journalctl -u docker -f --follow log in real time
+ + # Scenario 4 + ls -l home/user/backup.sh --to check the permission
+ chmod a+x home/user/backup.sh --gives permission to execute to all
+ ls -l home/user/backup.sh --verify all cmd has r-xr-xr-x permission
+ (or) chmod 755 will work --based on number system but it has all the group
+ + diff --git a/2026/day-08/day-08-cloud-deployment.md b/2026/day-08/day-08-cloud-deployment.md new file mode 100644 index 0000000000..c024e67993 --- /dev/null +++ b/2026/day-08/day-08-cloud-deployment.md @@ -0,0 +1,18 @@ +# Part 1: Launch Cloud Instance & SSH Access +Step 1: Create a Cloud Instance
+Step 2: Connect via SSH
+ +# Part 2: Install Docker & Nginx + Step 1: Update System --- sudo apt update
+ Step 3: Install Nginx -- sudo apt-get install nginx
+ Verify Nginx is running: -- systemctl status nginx
+ + # Part 3: Security Group Configuration + http://51.21.160.162/ + image + +# Part 4: Extract Nginx Logs +Step 1: View Nginx Logs --- cd /var/log/nginx
+ tail -f /var/log/nginx/access.log
+Step 2: Save Logs to File(~ home) --- cp -r error.log ~/nginx.txt
+Step 3: Download Log File to Your Local Machine --- scp -i shell-scripting.pem ubuntu@51.21.160.162:~/nginx.txt .
diff --git a/2026/day-09/day-09-user-management.md b/2026/day-09/day-09-user-management.md new file mode 100644 index 0000000000..7e79fa7a67 --- /dev/null +++ b/2026/day-09/day-09-user-management.md @@ -0,0 +1,49 @@ +# Task 1: Create Users +sudo adduser professor (password & details automatically asked)
+sudo adduser tokyo
+sudo useradd -m berlin -s usr/bin/bash ---craeteonly user name
+sudo passwd berlin ---to create password + +# Task 2: Create Groups +Create group named developers ----sudo addgroup developers +Create group named admins --- sudo addgroup admins + +# Task 3: Assign to Groups +sudo usermod -aG developers tokyo --tokyo → developers
+sudo usermod -aG developers,admins berlin ---berlin → developers + admins (both groups)
+sudo gpasswd -a professor admins --- professor → admins
+Check group after each step --- cat /etc/group
+ +# Task 4: Shared Directory +sudo mkdir -p /opt/dev-project ---Create directory: /opt/dev-project
+sudo chown :developers /opt/dev-project ----change owner to developer
+sudo chmod 775 /opt/dev-project/ --chnage permission
+image + +cd /opt/dev-project >>> su berlin --file created inside
+berlin@ip-172-31-43-101:/opt/dev-project$ touch berlin.txt --creates file
+ +cd /opt/dev-project >>> su tokyo --file created inside
+tokyo@ip-172-31-43-101:/opt/dev-project$ touch tokyo.txt
+ +#Testing negative scenario +This happened because owner is changed to developer so dev has tokyo and berlin added not professor +cd /opt/dev-project >>> su professor user enters
+image + +# Task 5: Team Workspace +sudo addgroup project-team --Create user nairobi with home directory
+sudo usermod -aG project-team niarobi
+sudo usermod -aG project-team tokyo
+image + +sudo mkdir -p /opt/team-workspace ---Create /opt/team-workspace directory
+image + +sudo chmod 775 /opt/team-workspace/ ---Set group to project-team, permissions to 775
+Test by creating file as nairobi
+image + +Learning :(both commands are simialr)
+sudo chown :project-team ubuntu
+sudo chgrp project-team ubuntu
diff --git a/2026/day-10/day-10-file-permissions.md b/2026/day-10/day-10-file-permissions.md new file mode 100644 index 0000000000..e1c3f1fdcd --- /dev/null +++ b/2026/day-10/day-10-file-permissions.md @@ -0,0 +1,26 @@ +# Task 1: Create Files +touch devops.txt --creating file
+touch notes.txt --creating file
+echo "This is devops" > notes.txt --entring data
+echo "This is appending" >> notes.txt --appending data
+vim script.sh --creating script and saving
+image + +# Task 2: Read Files +cat notes.txt ---Read notes.txt using cat
+vim script.sh ---View script.sh in vim read-only mode
+image + +# Task 3: Understand Permissions +Read write execute in devops.txt user and owner have read write permission
+image + +# Task 4: Modify Permissions + +image + +# Task 5: Test Permissions +image + + + diff --git a/2026/day-11/day-11-file-ownership.md b/2026/day-11/day-11-file-ownership.md new file mode 100644 index 0000000000..1254f7abec --- /dev/null +++ b/2026/day-11/day-11-file-ownership.md @@ -0,0 +1,24 @@ +# Task 1: Understanding Ownership +Owner - Single user Group - Collective multiple users +image + +# Task 2: Basic chown Operations +image + +# Task 3: Basic chgrp Operations +image + +# Task 4: Combined Owner & Group Change +image + +# Task 5: Recursive Ownership +image + +# Task 6: Practice Challenge +image + +# Learning +Group must exist before using in chgrp/chown
+standard groupadd command can only create one group at a time
+sudo chown -R professor:planners heist-project/ --here -R changes user and group for all files present inside in 1 go
+ diff --git a/2026/day-12/day-12-revision.md b/2026/day-12/day-12-revision.md new file mode 100644 index 0000000000..2aa3717f6e --- /dev/null +++ b/2026/day-12/day-12-revision.md @@ -0,0 +1,29 @@ +# Process Management +systemctl status nginx/docker --to check status of process
+systemctl start nginx/docker --- To start any process
+systemctl stop nginx/docker --- To Stop any process
+journalctl -u nginx/docker ---- to show all logs of an individual process
+ +# User Management +whoami ---- shoes which user is active
+sudo adduser xxx --- Adds user and made directory automatically
+sudo passwd xxx --- set up password for login
+su xxx --- command to enter inside user giving password (opens black bash)
+which bash --- which bash currently am i using (usually coloured) gives path
+sudo useradd -m yyy -s usr/bin/bash --- to make bash similar to **older coloured style** and using -m (Simialr to windows switching)
+cat /etc/group --- shows all the user group
+sudo addgroup ggg ---making group for user
+sudo gpasswd -a xxx ggg ---adding user inside group. here xxx is added in group ggg along **with permission** gets added
+sudo gpasswd -d xxx ggg ---To remove the user from that group and revoke their permissions. Restart with newgrp current user
+sudo usermod -aG docker ubuntu ---Adding an Ubuntu User to the docker Group to **avoid sudo** and have permissions
+sudo chown ggg filename.txt ---change the individual owner of the file from ubuntu to other user only valid for individual
+sudo chgrp xxx filename.txt --change group owner can be done with chown (:) as well
+# File System +Read (cat)
+Write (vim/nano)
+Execute (shell/ ./)
+mkdir -p devops -----makes directory **with path** without error even if it exists do not throw error
+vim hello.txt > Insert i > write content > Esc > :wq(save and quit)/:q!(exit without saving)
+newgrp ubuntu --- changes current active primary group to the group named ubuntu for your current terminal session
+-rwxrwxrwx --read write execute for **owner group others** in sets of 3
+chmod 777 ---giving all permission / chmod 400 ----giving only read permission
diff --git a/2026/day-13/day-13-lvm.md b/2026/day-13/day-13-lvm.md new file mode 100644 index 0000000000..aa1f34e7c2 --- /dev/null +++ b/2026/day-13/day-13-lvm.md @@ -0,0 +1,20 @@ +# Task 1-4 +image + +pvdisplay vgdisplay lvdisplay (similarly other) +image + +lsblk +image + +# Task 5 : Format and Mount +image +image + +# Additionl mounting from disk +image +image +image + +# Task 6: Extend the Volume +image diff --git a/2026/day-14/day-14-networking.md b/2026/day-14/day-14-networking.md new file mode 100644 index 0000000000..f4fcf9a09b --- /dev/null +++ b/2026/day-14/day-14-networking.md @@ -0,0 +1,108 @@ +# OSI Model(Open Systems Interconnection) +7. APPLICATION [Data] -> Human-computer interaction (HTTP, SMTP, DNS) +6. PRESENTATION [Data] -> Encryption, compression, syntax (SSL/TLS, JPEG) +5. SESSION [Data] -> Manages connections & dialogs (NetBIOS, RPC) +4. TRANSPORT [Segments] -> End-to-end delivery & flow control (TCP 3 way handshak, UDP 2 way handshake) +3. NETWORK [Packets] -> Routing & IP addressing (IPv4, IPv6, Routers) +2. DATA LINK [Frames] -> Physical addressing & switching (MAC, Switches) +1. PHYSICAL [Bits] -> Cables, voltage, and raw signals (Ethernet, Fiber) + +# Transmission Control Protocol/Internet Protocol +4. APPLICATION [Data] -> Apps, services, and formatting (HTTP, DNS, SSH) +3. TRANSPORT [Segments] -> Host-to-host delivery & flow control (TCP, UDP) +2. INTERNET [Packets] -> Routing, logical addressing (IPv4, IPv6, ICMP) +1. NETWORK ACCESS [Frames/Bits]-> Physical hardware and local link (Ethernet, Wi-Fi) + +# Example +Curl https://...../ + +[curl] ──> is an HTTP Request ──> over a TCP Segment ──> inside an IP Packet ──> over an Ethernet Frame + (Application) (Transport) (Internet) (Network Access) + +4. APPLICATION [Data] -> curl, curl -I, dig, nslookup +3. TRANSPORT [Segments] -> ss, netstat +2. INTERNET [Packets] -> ping, traceroute +1. NETWORK ACCESS [Frames] -> ip addr show + +--- + +## 🛠️ Layer-by-Layer Command Map (1-Liners) + +### Layer 4: Application Layer +* **`curl `** + * **Why it is used:** To request and download the full source code, files, or API data payloads from a web server. +* **`curl -I `** + * **Why it is used:** To grab *only* the HTTP metadata headers to quickly check website status codes (e.g., 200, 403, 404) and server security. +* **`dig `** + * **Why it is used:** To query DNS servers on UDP Port 53 and retrieve highly detailed technical records (A, MX, TXT) for a domain. +* **`nslookup `** + * **Why it is used:** To perform a simple, universal DNS lookup to quickly verify the raw IP address assigned to a human domain name. + +### Layer 3: Transport Layer +* **`ss -tulpn`** + * **Why it is used:** To look inside the local OS and see exactly which application names and Process IDs (PIDs) are listening on which TCP/UDP ports. +* **`netstat -an | head`** + * **Why it is used:** To look inside legacy systems and preview the first 10 rows of active socket connections and port mappings. + +### Layer 2: Internet Layer +* **`ping `** + * **Why it is used:** To send lightweight ICMP signals to check if a remote server is alive and measure connection latency in milliseconds. +* **`traceroute `** + * **Why it is used:** To map out the exact geographical path and pinpoint the response times of every single intermediate router hop to a destination. + +### Layer 1: Network Access Layer +* **`ip addr show`** + * **Why it is used:** To inspect local network hardware interfaces, look up physical MAC addresses, and verify if a network connection is active (UP/DOWN). + +--- + +## 📋 Quick Blueprint Summary + +```text +[Hardware Info] --> Layer 1 (Network Access) --> ip addr show +[Network Routing] --> Layer 2 (Internet) --> ping, traceroute +[OS Ports & Sockets] --> Layer 3 (Transport) --> ss, netstat +[App Code & Data] --> Layer 4 (Application) --> curl, dig, nslookup +``` + +# Hands-on Checklist +hostname -I ---Only the active IP addresses. A quick check to copy/paste your IP address.
+ip addr showIPs ---MAC addresses, connection status, MTU, and interface names. Deep network troubleshooting and checking physical link layer stats.
+ping -c 4 google.com --ping cmd test whether a specific network destination is online and reachable
+image + +traceroute google.com ---is used for network path visibility and pinpoint troubleshooting. acts like a GPS roadmap that tells you exactly where the breakdown is happening
+image + +sudo ss -tulpn --- Linux utility used to display active network sockets.
+Port Conflict Troubleshooting: If you try to launch a web server and it crashes saying "Port 80 already in use", running ss -tulpn will instantly reveal the exact process name and ID blocking that port.
+image + +nslookup google.com --A legacy, simple tool for a quick, straightforward IP verification. +[dig / nslookup] ──> Application Layer tools using UDP Port 53 to convert human domain names to Layer 3 IP addresses. +image + +dig google.com ---The modern highly detailed, showing exact server transaction times, response headers, and structured raw data.
+image + + curl -I google.com --Troubleshooting HTTP status codes: Instantly verify if a site returns 200 OK, 301 Redirect, 403 Forbidden, or 500 Server Error.
+ Analyzing Security & Server Software (Footprinting)
+ Verifying Cache and Content Types - It tells you what kind of file is sitting at the URL via the content-type
+ + +-----------------------+--------------------+---------------------------------------------------+ + +| COMMAND | TROUBLESHOOT LAYER | BEST USED FOR | ++-----------------------+--------------------+---------------------------------------------------+ + +| nc -zv localhost | Transport (TCP) | ANY port (SSH, MySQL, Redis). Just tests if the | +| | | application door is open or closed. | ++-----------------------+--------------------+---------------------------------------------------+ + +| curl -I http:// | Application (HTTP) | ONLY Web/API ports (80, 443, 8080). Tests if the | +| | | web software is responding correctly. | ++-----------------------+--------------------+---------------------------------------------------+ + +image + +netstat -an | head --(new is ss tulpn)troubleshooting pipeline used to check the very first few lines of your system's active network connections.
+image diff --git a/2026/day-15/day-15-networking-concepts.md b/2026/day-15/day-15-networking-concepts.md new file mode 100644 index 0000000000..44b9146f60 --- /dev/null +++ b/2026/day-15/day-15-networking-concepts.md @@ -0,0 +1,112 @@ +# Task 1: DNS – How Names Become IPs +When google.com is typed it checks corrosponding ip in local catche. If not found it send request to DNS resolver. +The query goes to root and checks if it exists then check TLD (.com) and finally Authoritative server to locate IP address to initaite a connection on given browser.
+ +### DNS Record Types +* **`A`**: Maps a human-readable domain name directly to an **IPv4** address. +* **`AAAA`**: Maps a human-readable domain name directly to an **IPv6** address. +* **`CNAME`**: Creates an alias that points one domain name to another domain name instead of an IP address. +* **`MX`**: Specifies the mail server responsible for accepting email messages on behalf of the domain name. +* **`NS`**: Identifies the authoritative name servers trusted to hold and manage the DNS records for the domain. + +image + +# Task 2: IP Addressing +What is an IPv4 address and how is it structured? +--.--.--.-- consists of 32 bits having 4 decimal can viewed in CIDR address way. +#### 2. Public vs. Private IPs +* **Public IP**: Globally unique and visible to the entire internet, allowing routers around the world to find your server. + * *Example:* `142.250.190.46` (Google's public web server) +* **Private IP**: Non-unique, local addresses used exclusively inside a closed local network and completely invisible to the public internet. + * *Example:* `192.168.1.25` (A typical home laptop address) + +--- + +#### 3. Private IP Ranges (RFC 1918) +* **10.x.x.x:** `10.0.0.0` to `10.255.255.255` (Large enterprise networks) +* **172.16.x.x – 172.31.x.x:** `172.16.0.0` to `172.31.255.255` (Medium cloud/VPC networks) +* **192.168.x.x:** `192.168.0.0` to `192.168.255.255` (Small home/office networks) + +--- + +#### 4. Identified Private IPs from `ip addr show` Output +Based on the live interface screenshots, this machine utilizes three distinct private IP addresses: +* **`172.31.43.101` (interface: `ens5`)**: Private Class B IP assigned by AWS VPC for local cloud routing. +* **`172.17.0.1` (interface: `docker0`)**: Private Class B IP acting as the local virtual bridge gateway for container traffic. +* **`127.0.0.1` (interface: `lo`)**: Local loopback address reserved exclusively for internal machine self-communication. + +# Task 3: CIDR & Subnetting +What does /24 mean in 192.168.1.0/24? +#### 1. Meaning of /24 in 192.168.1.0/24 +The `/24` notation (called CIDR notation) indicates that the first **24 bits** of the 32-bit IP address are locked and dedicated to identifying the **network portion**. The remaining 8 bits are left open to be dynamically assigned to individual devices (hosts) living inside that network. + +--- + +#### 2. Usable Hosts Calculation +* **In a `/24`**: **254 usable hosts** (Calculated as $2^8 - 2$). +* **In a `/16`**: **65,534 usable hosts** (Calculated as $2^{16} - 2$). +* **In a `/28`**: **14 usable hosts** (Calculated as $2^4 - 2$). +* *Note: We always subtract 2 because the very first address is reserved as the Network ID, and the very last address is reserved as the Broadcast address.* + +--- + +#### 3. Why We Subnet +Subnetting means breaking up one single massive network into smaller, isolated, and organized pieces. We do it for three major reasons: +1. **Security**: It keeps traffic isolated. For example, you can put vulnerable public web servers in one subnet and secure internal financial databases in another subnet, blocking traffic between them. +2. **Performance**: In a giant network, devices constantly broadcast signals to everyone. Subnetting puts up walls so noisy broadcast traffic stays inside its own small zone instead of slowing down the entire company. +3. **Efficiency**: It prevents wasting millions of IP addresses by tailoring the network size exactly to the number of devices that need it. + +--- + +#### 4. Quick Exercise Table + + +| CIDR | Subnet Mask | Total IPs | Usable Hosts | +| :--- | :--- | :--- | :--- | +| **/24** | `255.255.255.0` | 256 | **254** | +| **/16** | `255.255.0.0` | 65,536 | **65,534** | +| **/28** | `255.255.255.240` | 16 | **14** | + +# Task 4 Ports – The Doors to Services +### Task 4: Ports – The Doors to Services + +#### 1. Definition & Purpose +* **What it is:** A 16-bit number (0–65535) acting as a specific application doorway inside an OS. +* **Why we need them:** IP addresses route data to the **machine**; ports route data to the specific **software service**. They allow a single server to run multiple network applications simultaneously (e.g., hosting a website while allowing SSH access). + +--- + +#### 2. Common Ports Reference + + +| Port | Service | Core Function | +| :--- | :--- | :--- | +| **22** | **SSH** | Secure remote server management. | +| **80** | **HTTP** | Standard, unencrypted web traffic. | +| **443** | **HTTPS** | Secure, encrypted web traffic (SSL/TLS). | +| **53** | **DNS** | Domain name resolution to IP addresses. | +| **3306** | **MySQL** | Relational database connection endpoint. | +| **6379** | **Redis** | Fast, in-memory caching and data store. | +| **27017**| **MongoDB** | NoSQL document database connection endpoint. | + +--- + +#### 3. Live Screen Mapping (`sudo ss -tulpn`) +Two active ports identified and verified directly from the system logs: +* **Port 80 $\rightarrow$ Nginx (`nginx`)**: The web server software actively waiting on Port 80 to deliver HTTP web content. +* **Port 22 $\rightarrow$ SSH Daemon (`sshd`)**: The secure shell mechanism holding open Port 22 to maintain this terminal configuration session. + +# Task 5: Putting It Together + +## 📝 Scenario Analysis & Troubleshooting + +### 1. Concepts in `curl http://myapp.com:8080` +* **DNS Resolution:** Translating `myapp.com` to a Layer 3 IP address. +* **TCP Transport:** Opening a reliable connection over custom **Port 8080**. +* **HTTP Application:** Sending an unencrypted web request to fetch application data. + +--- + +### 2. First Checks for Database Failure (`10.0.1.50:3306`) +* **Run `ping 10.0.1.50`:** Confirms if the machine is alive inside the private subnet. +* **Run `nc -zv 10.0.1.50 3306`:** Checks if the MySQL database application is listening or if a firewall is blocking that specific port. diff --git a/2026/day-16/day-16-shell-scripting.md b/2026/day-16/day-16-shell-scripting.md new file mode 100644 index 0000000000..105b2679a6 --- /dev/null +++ b/2026/day-16/day-16-shell-scripting.md @@ -0,0 +1,57 @@ +# Task 1 +vim hello.sh +ls -l hello.sh +chmod 775 hello.sh +./hello.sh +Without shebang it displays the same result. + +# Task 2 + +#!/bin/bash +NAME=Sharat +ROLE=DevopsEngineer +echo "Hello, I am $NAME and I am $ROLE" +echo 'Hello, I am $NAME and I am $ROLE' + +# Task 3 +vim greet.sh +#!/bin/bash +read -p "Enter your name :" Name +read -p "enter you favourite tool :" Tool +echo "Hello $Name your favourite tool is $Tool" + +# Task 4 + +#!/bin/bash +read -p "Enter a number: " Number +if [ $Number -gt 0 ];then + echo " $Number is positive" +elif [ $Number -lt 0 ];then\ + echo "$Number is negative" +else echo "The number is zero" +fi + +#!/bin/bash +read -p "Enter the filename :" Filename +if [ -f $Filename ]; then + echo "$Filename already exist" +else + echo " Your $Filename dosenot exist" +fi + +# Task 5 + +#!/bin/bash +Servicename="nginx" +read -p "Do you want to check service status for $Servicename. Enter Y or N :" Enter +if [[ $Enter == 'Y' ]]; then + echo "Checking status for $Servicename ...." + systemctl status "$Servicename" --no-pager + if systemctl is-active "$Servicename"; then + echo "$Servicename is running" + else + echo "$Service is not active" + fi +else + echo " Thanks for the $Servicename exploration!!" +fi diff --git a/2026/day-17/day-17-scripting.md b/2026/day-17/day-17-scripting.md new file mode 100644 index 0000000000..d6e56243cc --- /dev/null +++ b/2026/day-17/day-17-scripting.md @@ -0,0 +1,78 @@ +# Task 1 For Loop +Loop of 5 fruits +#!/bin/bash + +echo "list of fruits are :" + +for i in {apple,mango,banana,grapes,kiwi} +do + echo "$i" +done + +----------------Loop of number 1to 10 +#!/bin/bash + +echo "the numbers between 1 to 10 :" + +for (( i = 1; i<=10; i++ )) +do + echo "$i" +done + +# Task 2 While Loop + +#!/bin/bash +read -p "Enter the numbers :" num + +echo "Number in reverse order are" +while (( num > 0 )) +do + echo "$num" + (( num-- )) +done + +# Task 3 Arguments with $ signs +#!/bin/bash + + +if [ -z "$1" ];then + echo "Usage: ./greet.sh" + exit 1 +else + + echo "Hello $1 !!" +fi + +----demo arguments +#!/bin/bash + +echo " total number of arguments entered : $#" + +echo " all the arguments are $@" + +echo " the script name is : $0" + +# Task 4 Pakagae_Installation +#!/bin/bash + +for i in nginx curl wget +do + if dpkg -s "$i" >/dev/null 2>&1; then + echo "Pakage already exists ..." + else + echo "Installing pkg ...." + sudo apt-get update && sudo apt-get install -y "$i" + fi +done + +# Task 5 Error_Handling +#!/bin/bash + +set -e + +mkdir /home/ubuntu/devops-test || echo "Directory already exist" + +echo "Navigating inside directory .../home/ubuntu/devops-test" +cd /home/ubuntu/devops-test +echo "creating file inside new directory.." +touch file.txt diff --git a/2026/day-18/day-18-scripting.md b/2026/day-18/day-18-scripting.md new file mode 100644 index 0000000000..15c7f99c0c --- /dev/null +++ b/2026/day-18/day-18-scripting.md @@ -0,0 +1,138 @@ +# Task 1 +#!/bin/bash + +greet() +{ + echo "hello $1 !!!" +} + +add() +{ + echo "The sume of 2 numbers $1 and $2 is :" + local a=$1 + local b=$2 + local sum=$(( a + b )) + echo "$sum" +} + +greet "$1" +add "$2" "$3" + +# Task 2: Functions with Return Values +#!/bin/bash + +check_disk() +{ + echo " currect working directory" + pwd + echo "$pwd" + echo "Going to root directory..." + cd / && df -h + +} + +check_memory() +{ + echo " currect working directory" + pwd && echo "$pwd" + echo "Going to root directory..." + cd / && free -h + +} + +check_disk +check_memory + +# Task 3: Strict Mode — set -euo pipefail +#!/bin/bash + +set -euo pipefail + +echo "=== STAGE 1: Testing 'set -u' (Undefined Variables) ===" +echo "$name is sharat" + +echo "=== STAGE 2: Testing 'set -e' (Failing Commands) ===" +commamd +echo "Command is a fake command" + +echo "=== STAGE 3: Testing 'set -o pipefail' (Piped Failures) ===" +command | grep --color=never "anything" + +Results : ./strict_demo.sh: line 6: name: unbound variable + ./strict_demo.sh: line 9: commamd: command not found + ./strict_demo.sh: line 13: anything: command not found + +# Task 4 Local Variables +#!/bin/bash + +safe() +{ + local a="password" + echo "$a is safe" +} + +leak() +{ + b="pass" + echo "$b" +} + +echo"$a" +safe + +leak +echo "may be leaked value $b " + + Result : password is safe + pass + may be leaked value pass + +# Task 5 Build a Script — System Info Reporter +#!/bin/bash +set -euo pipefail +host() +{ + echo "OS Details" + source /etc/os-release && echo "$PRETTY_NAME" + echo " Hostname : $(hostname) " + +} + +time_up() +{ + uptime -p +} + +disk_use() +{ + df -h --output=source,size | head -n 5 +} + +mem() +{ + ps -o pid,pmem,comm --sort=-pmem |head -n 5 +} +main() +{ + host + time_up + disk_use + mem +} +main + +Result : +OS Details +Ubuntu 26.04 LTS + Hostname : ip-172-31-43-101 +up 6 hours, 11 minutes +Filesystem Size +/dev/root 6.7G +tmpfs 455M +tmpfs 182M +efivarfs 128K + PID %MEM COMMAND + 16945 1.3 vim + 23108 0.7 head + 10415 0.6 bash + 23107 0.4 ps diff --git a/2026/day-19/day-19-project.md b/2026/day-19/day-19-project.md new file mode 100644 index 0000000000..d453309bde --- /dev/null +++ b/2026/day-19/day-19-project.md @@ -0,0 +1,111 @@ +# Task 1: Log Rotation Script +#!/bin/bash + +log_rotate() +{ +if [ $# -eq 0 ]; then + echo " Enter the source path " + exit 1 +fi + log="$1" + count=$( find "$log" -name "*.log" -type f -mtime +7 | wc -l ) + + find "$log" -name "*.log" -type f -mtime +7 -exec gzip {} + + + + countd=$(find "$log" -name "*.gz" -type f -mtime +30 | wc -l) + + find "$log" -name "*.gz" -type f -mtime +30 -exec rm {} + + + echo "File Compressed : $count" + echo "File deleted : $countd" +} +log_rotate "$1" + + # Task 2: Server Backup Script + #!/bin/bash + +if [ $# -lt 2 ]; then + echo " enter source and destination :" +fi + + src="$1" + dest="$2" + + if [ ! -d "$src" ]; then + echo "Source missing" + exit 1 + fi + + mkdir -p "$dest" + + filename="backup_$(date +%Y-%m-%d).tar.gz" + fullpath="$dest/$filename" + + tar -czf "$fullpath" "$src" + + if [ -f "$fullpath" ]; then + echo "Backup created for $filename" + echo "Size : $(du -h "$fullpath" | cut -f1)" + + find "$dest" -name "backup_*.tar.gz" -mtime +14 -exec rm {} + + fi + +# Task 3: Crontab(file timing is crutial min for min cron) +#!/bin/bash +set -euo pipefail + +backup() +{ +#1Hardcoded Paths +src="/home/ubuntu/devops-test" +dest="/home/ubuntu/devops" + +mkdir -p "$dest" + +#2 Crucial Time format so filenames change EVERY minute +filename="backup_$(date +%Y-%m-%d_%H%M).tar.gz" +fullpath="$dest/$filename" + +#3 Create the archive +tar -czf "$fullpath" "$src" + +#4 Print verification +if [ -f "$fullpath" ]; then + echo "Backup created for $filename" + echo "Size : $(du -h "$fullpath" | cut -f1)" + + # Clean up backups older than 14 days + find "$dest" -name "backup_*.tar.gz" -mtime +14 -exec rm {} + +fi +} +backup + +# Task 4: Combine — Scheduled Maintenance Script + +#!/bin/bash + +source /home/ubuntu/log_rotate.sh +source /home/ubuntu/backup.sh + + log="/var/log/maintenance.log" + + exce >> "$log" 2>&1 + + #Print timestamped start banner +echo "=== Maintenance Started: $(date '+%Y-%m-%d %H:%M:%S') ===" + + echo "Rotation log" + log_rotate "/home/ununtu/devops-test" + + echo "Backup" + backup + echo "=== Maintenance Completed: $(date '+%Y-%m-%d %H:%M:%S') ===" + +Result: sudo ./maintenance.sh /home/ubuntu/devops-test +File Compressed : 2 +File deleted : 2 +tar: Removing leading `/' from member names +Backup created for backup_2026-05-29_1203.tar.gz +Size : 12M + diff --git a/2026/day-20/day-20-solution.md b/2026/day-20/day-20-solution.md new file mode 100644 index 0000000000..fefcfa37d4 --- /dev/null +++ b/2026/day-20/day-20-solution.md @@ -0,0 +1,90 @@ +# Task 1: Input and Validation +#!/bin/bash + +#Exit immediately if a command fails (-e) or an unset variable is used (-u) +set -euo pipefail + +#1. Check if the user forgot to provide a file path argument +if [ $# -eq 0 ]; then + echo "ERROR: No log file path provided." >&2 + echo "Usage: $0 " >&2 + exit 1 +fi +log="$1" +if [ ! -f "$log" ];then + echo "ERROR: File '$log' does not exist." >&2 + exit 1 +fi +echo "Success: File '$log' found and ready for analysis." + +Result: ./log_analyzer.sh /var/log/maintenance.log +Success: File '/var/log/maintenance.log' found and ready for analysis. + +# Task 2: Error Count(cont..of task1 code) + + err=$(grep -E "ERROR|Failed" "$log" | wc -l || true) + + echo "Total number of lines : $err " + +Result : ./log_analyzer.sh /var/log/maintenance.log +Success: File '/var/log/maintenance.log' found and ready for analysis. +Total number of lines : 4 + + # Task 3: Critical Events( cont... task1) + +grep -n "CRITICAL" "$log" | awk -F':' '{print "Line " $1 ": " $2}' || true + +REsult : ./log_analyzer.sh /var/log/maintenance.log +======TASK 3============= +Line8:2026-05-29 14 +Line9:2026-05-29 14 + +# Task 4: Top Error Messages( cont... task1) + echo "======TASK 4=============" + grep -E "ERROR" "$log" | sed -E 's/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} //' | sort | uniq -c | sort -rn |head -5 ||true + +# Task 5: Summary Report + + echo "=====TASK 5========" + + curdate=$(date +%Y-%m-%d) + logfile="log_report_${curdate}.txt" + LOG_FILENAME=$(basename "$log") + + totline=$(wc -l < "$log" ) + + # FIX 1: Added -Ei for case matching and pointed it to "$log" file + errline=$(grep -Ei "ERROR|Failed" "$log" | wc -l || true) + + # FIX 2: Corrected the target search pattern to "ERROR" and added "$log" file + toperr=$(grep -E "ERROR" "$log" | sed -E 's/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} //' | sort | uniq -c | sort -rn | head -5 || true) + + # FIX 3: Extracted critical events cleanly to populate the report variable + CRITICAL_EVENTS=$(grep -n "CRITICAL" "$log" | awk -F':' '{print "Line " $1 ": " $2}' || true) + + { + echo "==================================================" + echo " DAILY LOG SUMMARY REPORT " + echo "==================================================" + echo "Date of Analysis: $curdate" + echo "Log File Name: $LOG_FILENAME" + echo "Total Lines Processed: $totline" + echo "Total Error Count: $errline" + echo "--------------------------------------------------" + echo "Top 5 Error Messages:" + if [ -z "$toperr" ]; then + echo "None detected." + else + echo "$toperr" + fi + echo "--------------------------------------------------" + echo "Critical Events:" + if [ -z "$CRITICAL_EVENTS" ]; then + echo "None detected." + else + echo "$CRITICAL_EVENTS" + fi + echo "==================================================" +} > "$logfile" + +echo -e "\n[INFO] Summary report successfully generated: $logfile" diff --git a/2026/day-21/shell_scripting_cheatsheet.md b/2026/day-21/shell_scripting_cheatsheet.md new file mode 100644 index 0000000000..9955f87d92 --- /dev/null +++ b/2026/day-21/shell_scripting_cheatsheet.md @@ -0,0 +1,365 @@ +# Task 1: Basics +1.Shebang (#!/bin/bash) — Its says kernal what type of content is present
+2.Running a script : chmod +x ---gives permission(rwx) , + ./script.sh --cmd to execute bash script.sh---ignore shebang force execution using bash
+3.Comments — single line (#) and inline---- singel line comment
+4.Variables — declaring, using, and quoting ($VAR, "$VAR", '$VAR') +5.declearing variable using $VAR , using same variable "$VAR" , '$VAR' traeating character as literals strings not variable
+6.Reading user input —---read -p "Enter..." VAR : This is way to call from user
+7.Command-line arguments — $0(usually file name), $1(First arg), $#(Number of Arg), $@(dispaly all arg entered by user), $?(exit status of the last executed command)
+ +# Task 2: Operators and Conditionals +1.String comparisons — = strings are equal, != strings are not equal, -z true if string is empty, -n true when string is non empty
+2.Integer comparisons — -eq(equal to), -ne(notn equal to), -lt(les than), -gt(greater than), -le(less than), -ge(greater then equals)
+3.File test operators — -f (true for file), -d(true for directory), -e(true for path), -r(gives read), -w (gives write), -x(execute), -s (file exist)
+4.if []; then, elif []; then, else syntax---of else if +5.Logical operators — && (both are true), ||(one is true), !(logical not) +6.Case statements — case ... esac : cases + +# Task 3: Loops +Document with examples: +1. `for` loop — list-based and C-style + + #Iterating over explicit items +for color in Red Green Blue; do + echo "Color: $color" +done + +#Iterating over a number range {start..end..step} +for i in {1..5..2}; do + echo "Number: $i" +done + +#C Style +for ((i=1; i<=3; i++)); do + echo "Count: $i" +done + +2. `while` loop + count=1 +while [ $count -le 3 ]; do + echo "Value: $count" + ((count++)) # Increment the variable +done + +3. `until` loop + count=1 +until [ $count -gt 3 ]; do + echo "Value: $count" + ((count++)) +done + +4. Loop control — `break`, `continue` + for num in {1..5}; do + if [ $num -eq 2 ]; then + continue # Skip the rest of the code for number 2 + fi + if [ $num -eq 5 ]; then + break # Exit the loop completely when reaching 5 + fi + echo "Number: $num" +done + +5. Looping over files — `for file in *.log` + #Process all log files in the current directory +for file in *.log; do + #Check if files actually exist to avoid running on literal '*.log' + if [ -f "$file" ]; then + echo "Processing file: $file" + fi +done + +6. Looping over command output — `while read line` + + #Reading line-by-line from a command pipeline +df -h | while read -r line; do + echo "Disk info: $line" +done + +#Reading line-by-line directly from a file +while read -r line; do + echo "Line content: $line" +done < input.txt + +# Task 4: Functions +1. Defining a function — function_name() { ... } + #Definition +show_welcome() { + echo "Welcome to the system automation script!" +} + +2. Calling a function + #Call the function defined above + show_welcome + +3. Passing arguments to functions — $1, $2 inside functions + #Define a function that expects two inputs +show_user_info() { + echo "The username is: $1" + echo "The assigned role is: $2" +} + +#Call the function and pass two string arguments +show_user_info "admin_user" "System Administrator" + +4. Return values — return vs echo +#Method 1: Using 'return' for success/failure checks +check_root() { + if [ "$USER" = "root" ]; then + return 0 # Success + else + return 1 # Error/Failure + fi +} + +#Method 2: Using 'echo' to send back actual data strings +calculate_tax() { + local total=$(($1 * 2)) + echo "$total" +} + +#Running Method 1 +check_root +echo "Exit status was: $?" + +#Running Method 2 (Capturing output into a variable) +final_bill=$(calculate_tax 50) +echo "The calculated tax amount is: $final_bill" + +5. Local variables — local + #!/bin/bash + +#A global variable +CITY="Berlin" + +update_location() { + # Local variable: only exists inside this function + local CITY="Paris" + echo "Inside function, CITY is: $CITY" +} + +#Run the function +update_location + +#Check global variable value +echo "Outside function, CITY is still: $CITY" + +Result: +Inside function, CITY is: Paris +Outside function, CITY is still: Berlin + +# Task 5: Text Processing Commands + +1. grep — Search PatternsUsed to search text files for lines matching a specified pattern.
+-i: Ignores character case (matches both error and ERROR).
+-r: Recursively searches all files inside directories and subdirectories.
+-c: Displays only the numerical count of matching lines instead of the text.
+-n: Displays the line number in the file where the match was found.
+-v: Inverts the match, printing only lines that do not match the pattern.
+-E: Enables Extended Regular Expressions (ERE) for complex patterns using | or ?.
+ +2. awk — Field Processing and Patterns +1, $2, $NF: Represents column numbers.
+$NF automatically references the very last column.
+-F: Defines a custom field separator character (defaults to whitespace).
+BEGIN { ... }: Executes commands before any text rows are processed.
+END { ... }: Executes commands after all text rows have been processed.
+ +Example : +#Print the 1st and 3rd columns from a colon-separated file (like /etc/passwd) +awk -F':' '{print $1, $3}' /etc/passwd + +#Print lines where the 3rd column value is greater than 100 +awk '$3 > 100 {print $0}' data.txt + +3. sed — Stream Editor +s/search/replace/g: Substitutes 'search' with 'replace' globally across the line.
+d: Deletes targeted lines matching a pattern or line number.
+-i: Edits the file in-place directly instead of printing output to the terminal screen.
+ +Example : +#Replace 'http' with 'https' globally in a file and save changes directly +sed -i 's/http/https/g' config.txt + +#Delete line 5 from a text file +sed '5d' data.txt + +4. cut — Extract Columns + -d: Sets the custom delimiter character (must be a single character).
+-f: Specifies which fields/columns to extract (e.g., -f1 or -f2,4).
+-c: Extracts specific character positions or ranges instead of columns.
+ +Example : +#Extract the 1st and 2nd columns from a comma-separated CSV file +cut -d',' -f1,2 addresses.csv + +5. sort — Arrange Lines +-n: Sorts values numerically rather than treating them as standard string text.
+-r: Reverses the sorted output order (e.g., descending instead of ascending).
+-u: Outputs only unique matching rows, throwing away exact duplicates.
+ +Example : +#Sort log file numbers numerically in reverse order +sort -nr prices.txt + +6. uniq — Deduplicate and CountFilters or displays duplicate lines from an input source. Note: uniq only detects adjacent duplicate lines, so you must run sort before it.
+-c: Prefixes each unique line with the total number of times it occurred. +-u: Prints only unique lines that never repeat in the file. +-d: Prints only lines that have matching duplicate copies. + +Example : +#Find unique lines and count their occurrences +sort names.txt | uniq -c + +7. tr — Translate or Delete Characters + Transforms, squeezes, or deletes characters from standard input. It does not accept filenames directly as arguments. + -d: Deletes specified target characters from the input text stream entirely.
+ -s: Squeezes repeating identical characters down to a single character instance.
+ +Example: +#Convert all lowercase text to uppercase characters +echo "hello world" | tr 'a-z' 'A-Z' + +#Delete all carriage return characters (\r) from a Windows text file +tr -d '\r' < windows.txt > linux.txt + +8. wc — Word CountCalculates counts for lines, words, and characters inside data.
+ -l: Displays the total line count.-w: Displays the total word count.
+ -c: Displays the total byte/character count.
+ + Example : + #Count how many total lines are present inside a log file + wc -l system.log + +10. head / tail — File InspectionDisplays portions from the beginning or absolute end of text files.
+ -n X: Limits output to exactly X lines (e.g., -n 5 or -n 20).
+ -f: (Tail only) Enters continuous follow mode, printing new log lines onto the screen in real-time as they are written.
+ + Example : + #View the first 5 lines of a configuration file + head -n 5 setup.conf + + #Watch a system log update in real-time as events occur + tail -f /var/log/syslog + +# Task 6: Useful Patterns and One-Liners + +1. Find and Delete Files Older Than 30 Days + + find /var/log/app/ -type f -name "*.log" -mtime +30 -delete + +2. Track Top 5 Error Sources in Real Time (Tail + Filter) + + tail -f /var/log/syslog | grep --line-buffered -i "error" | awk '{print $5, $6}' + +3. Replace a String Across Multiple Files In-Place + + grep -rl "http://old-api.local" ./src/ | xargs sed -i 's|http://old-api.local|https://production.com|g' + +4. Check if a Service is Running (With Action) + + systemctl is-active --quiet nginx || (echo "Nginx down! Restarting..." && systemctl start nginx) + +5. Aggregate and Count HTTP Status Codes from a Log + + awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -nr + +# Task 7 : Error Handling and Debugging + +1. Exit Codes — $?, exit 0, exit 1 + exit 0: Terminates the script and signals absolute success. + exit 1 (or any value up to 255): Terminates the script and signals a specific error. + + Example : + #!/bin/bash + +TARGET_FILE="/etc/missing_config.conf" + +if [ ! -f "$TARGET_FILE" ]; then + echo "Critical Error: Configuration file missing!" + exit 1 # Stops script immediately, returns status 1 +fi + +echo "File found." +exit 0 # Script finished successfully + +2. set -e — Exit on Error + +#!/bin/bash +set -e + +#If this directory does not exist, the script stops right here +cd /non/existent/directory + +#This line will never execute because of 'set -e' +echo "This message will not print." + +3. set -u — Treat Unset Variables as Error + +#!/bin/bash +set -u + +USER_NAME="Alice" + +#Typo in variable name throws an error and crashes the script safely +echo "Welcome, $USER_NAM" + +4. set -o pipefail — Catch Errors in Pipes + + #!/bin/bash +#Without pipefail, this entire line returns 0 (success) because wc succeeds +#With pipefail, this line returns a non-zero failure because cat fails +set -o pipefail + +cat non_existent_file.txt | wc -l +echo "Pipeline exit status: $?" + +5. set -x — Debug Mode (Trace Execution) ---Prints every command to the terminal screen exactly as it gets executed, with variables fully expanded. + + #!/bin/bash + +#Turn on debugging trace +set -x + +PREFX="Backup" +DATE=$(date +%F) +FILENAME="${PREFX}_${DATE}.tar.gz" + +#Turn off debugging trace +set +x + +echo "Generated: $FILENAME" + +Result : ++ PREFX=Backup +++ date +%F ++ DATE=2026-05-31 ++ FILENAME=Backup_2026-05-31.tar.gz ++ set +x +Generated: Backup_2026-05-31.tar.gz + +6. Trap — trap 'cleanup' EXIT ---Allows you to intercept system signals or script termination. + +#!/bin/bash +set -e + +#Define a cleanup function +cleanup_temp_files() { + echo "Cleaning up temp directory..." + rm -rf "$TEMP_DIR" +} + +#Register the trap: Run the function whenever the script exits +trap cleanup_temp_files EXIT + +#Create a temporary working workspace +TEMP_DIR=$(mktemp -d) +echo "Working in: $TEMP_DIR" + +#Simulate a script failure +ls /invalid/folder/path + +Result : + Working in: /tmp/tmp.jK98dx2Z +ls: cannot access '/invalid/folder/path': No such file or directory +Cleaning up temp directory...