• Contact
  • About Me
  • Privacy Policy
DefenceDev
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
No Result
View All Result
DefenceDev
No Result
View All Result
ADVERTISEMENT
Home Linux Tutorials Bash Scripting Tutorials

Lesson 11: Practical Linux Bash Examples and Projects

neo by neo
May 27, 2025
in Bash Scripting Tutorials
0
Lesson 11: Practical Linux Bash Examples and Projects

Lesson 11: Practical Linux Bash Examples and Projects

0
SHARES
14
VIEWS
Share on FacebookShare on Twitter
ADVERTISEMENT

Lesson 11: Practical Linux Bash Examples and Projects

Welcome to Lesson 11: Practical Linux Bash Examples and Projects. Mastering the Linux command line and Bash scripting can greatly boost your productivity. In this lesson, we will explore practical Bash examples and projects. These examples show how to apply Bash scripting to real-world tasks.

Introduction

This lesson is designed for Linux users who want to automate tasks, simplify processes, and solve challenges. We’ll focus on hands-on examples to help you work more efficiently.

Some key topics we’ll cover include:

  • Automating System Maintenance: Use Bash scripts to automate tasks like system updates, file clean-up, and backups.
  • File Manipulation: Learn to move, copy, delete, and organize files with Bash scripts.
  • Text Processing with Regular Expressions: Discover how to use grep, sed, and awk for searching and editing text.
  • Batch Renaming Files: Write scripts to rename or organize large sets of files, useful for things like photo sorting or log file management.
  • Scheduling Tasks with Cron: Use cron to schedule and automate Bash scripts at specific times.

These practical examples and projects demonstrate the versatility and power of Bash scripting. By applying these scripts to real-world tasks, you can automate repetitive processes, improve system management, and enhance your overall productivity.


Example 1: Solution: Automate Daily Backup of Remote Ubuntu Server Folder with a Bash Script

Backing up important data from remote servers to local systems is a critical part of maintaining data integrity and system reliability. In this script, we automate the process of synchronizing a remote folder with a local backup directory using the rsync tool.

ADVERTISEMENT
Key Features
  • Logs the time the backup operation starts.
  • Initiates a synchronization process between a remote system and a local server.
  • Logs all output to a dedicated backup log file for tracking and troubleshooting
Solution: Automate Daily Backup of Remote Ubuntu Server Folder with a Bash Script

Example 2: Solution: CPU Temperature Monitoring on Raspberry Pi4

Monitoring system temperatures is crucial for ensuring hardware stability and preventing overheating, especially in servers and high-performance machines. This script provides a simple solution to periodically check the temperature of your system and log the data for future reference.

Key Features
  1. Logs Temperature Data: The script reads the temperature of the system’s sensors (e.g., temp1 from sensors) and logs it with a timestamp to a log file.
  2. Daily Log Files: The log file is named based on the date, ensuring that each day’s temperature readings are stored separately.
  3. Continuous Monitoring: The script runs in an infinite loop, capturing temperature readings every 10 minutes (sleep 600), and checks if the date has changed to create a new log file for the next day.
Solution: CPU Temperature Monitoring on Raspberry Pi4

Example 3: Solution: Ubuntu Internet Connection Monitoring Script (Create a Log File, Possible to Send per Email)

In many cases, maintaining an active internet connection is crucial for servers or devices that rely on online services or monitoring. This script automates the process of checking the internet connection by pinging a specific IP address. If connectivity fails repeatedly, the script logs the failure and can trigger actions to remedy the issue.

Key Features
  1. Ping Monitoring: The script continuously pings a remote IP address (set to 8.8.8.8 by default, which is Google’s DNS server) to check connectivity.
  2. Logging Failed Pings: If the connection is lost, the script logs each failure, recording the time and the number of consecutive lost pings.
  3. Threshold for Failure: If a specified number of consecutive pings fail, the script logs an alert and takes further actions, such as restarting a service or notifying an administrator.
  4. Daily Log Files: It creates a new log file each day to store the results of the connectivity checks.
https://defencedev.com/linux-tutorial-basic/networking/solution-ubuntu-internet-monitoring-script-create-a-log-and-once-per-day-send-an-email/

Example 4: Solution: Connect from Ubuntu to the FortiGate Firewall and Execute Command (Bash Script)

Managing network interfaces effectively is essential for troubleshooting network connectivity or applying temporary configuration changes. This script automates the process of disabling and enabling the wan1 interface on a FortiGate device via SSH.

ADVERTISEMENT
ADVERTISEMENT
Key Features
  1. SSH Command Execution: The script connects to the FortiGate device using SSH on a custom port (default 11022) and sends the commands necessary to disable and enable the wan1 interface.
  2. Logging: The script logs each significant action, such as disabling and enabling the interface, with timestamps. It saves the log file to a location on the local server for tracking the script’s execution.
  3. Time Delay: The script waits for 60 seconds between disabling and enabling the interface, providing enough time for any network changes to take effect.
  4. Password Handling: Passwords are currently passed as plain text using sshpass, though it’s highly recommended to use SSH keys or prompt for passwords securely to avoid hardcoding them in scripts.
Solution: Connect from Ubuntu to the FortiGate Firewall and Execute Command (Bash Script)

«Previous: Lesson 10: Bash File Operation (Read, Write, Copy)
Next: Linux Process, List all Running Services with ps Command»

About The Author

neo

See author's posts

Tags: bash-scripting
ADVERTISEMENT
Previous Post

Lesson 10: Bash File Operation (Read, Write, Copy)

Next Post

Linux Process, List all Running Services with ps Command

neo

neo

Next Post
Linux Process, List all Running Services with ps Command

Linux Process, List all Running Services with ps Command

Follow Us

  • Trending
  • Comments
  • Latest
MikroTik: Export Configuration in Text File

MikroTik: Export Configuration in Text File

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Immich: Installation on Ubuntu 22.04

Immich: Installation on Ubuntu 22.04

Fortinet FortiGate Upgrade Path Tool

Fortinet FortiGate Upgrade Path Tool

NextCloud: Port Forwarding - Essential Ports for Smooth Functionality

NextCloud: Port Forwarding – Essential Ports for Smooth Functionality and Remote Access

Organizing and Managing Photos with Immich: Features I Use

Organizing and Managing Photos with Immich: Features I Use

Install Ubuntu 22.04 on Oracle VM Virtual Box

Install Ubuntu 22.04 on Oracle VM Virtual Box

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Recent News

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

MikroTik: Check Your Wireless Password

MikroTik: Check Your Wireless Password

ADVERTISEMENT

DefenceDev Tutorials

defencedev Logo

Whether you’re just starting or looking to expand your skills, I hope you find useful information and engaging discussions here. Let me take you through my journey and the goals behind this space!

Follow Us

Browse by Category

  • Blog
  • Cloud
    • Private
  • Linux Tutorials
    • Bash Scripting Tutorials
    • Commands
    • Networking
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Solutions
    • Docker
  • Video Tutorials
    • MikroTik Videos

Recent News

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

  • Site Map
  • Privacy Policy
  • Facebook Page
  • Disclaimer
  • Contact
  • About Me

© 2025 defencedev.com - All rights reserved.

No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos

© 2025 defencedev.com - All rights reserved.