Skip to content

This project is designed to help beginners and intermediate users learn and practice shell scripting through a collection of well-documented scripts and examples.

Notifications You must be signed in to change notification settings

waseemofficial/shell-script-basic

Repository files navigation

Languages

Python JavaScript Golang Java Solidity SQL Bash Bash

Technologies

Docker Linux Node.js React Redis Cypress Cypress GitHub GitHub GitHub GithubActions

Shell Script Basics Repository

Overview

Welcome to the Shell Script Basics repository! This project is designed to help beginners and intermediate users learn and practice shell scripting through a collection of well-documented scripts and examples. Whether you're automating tasks, managing system operations, or exploring DevOps workflows, this repository provides a solid foundation for mastering shell scripting.

Key Features

  • Beginner-Friendly: Simple and easy-to-understand scripts for those new to shell scripting.
  • Practical Examples: Real-world use cases, such as file management, system monitoring, and automation.
  • Modular Design: Scripts are organized into categories for easy navigation and reuse.
  • Comprehensive Documentation: Each script includes comments and explanations to help you understand its functionality.

Technologies and Tools Used

This repository leverages a variety of technologies and programming tools to ensure robust and efficient scripting:

  • Bash (Bourne Again Shell): The primary scripting language used for all examples.
  • Unix/Linux Commands: Core utilities like grep, awk, sed, find, and tar are extensively used.
  • Automation Tools: Scripts integrate with tools like cron for scheduling tasks.
  • Version Control: Managed with Git and hosted on GitHub for collaboration and version tracking.
  • Testing Frameworks: Basic testing is performed using BATS (Bash Automated Testing System) for script validation.
  • Text Processing: Advanced text manipulation using sed and awk for pattern matching and data extraction.
  • System Monitoring: Scripts for monitoring CPU, memory, and disk usage using commands like top, free, and df.
  • File Management: Examples include backup scripts, log rotation, and file synchronization using rsync and tar.
  • APIs and Integration: Scripts demonstrate interaction with APIs (e.g., GitHub, Jira) using curl.

Repository Structure

Here’s an overview of the repository structure:

shell-script-basic/
├── backups/                # Scripts for automated backups
├── monitoring/             # System monitoring and alerting scripts
├── file-management/        # File operations and synchronization
├── automation/             # Task automation and scheduling
├── api-integration/        # Examples of API interactions
├── tests/                  # Test cases for scripts
├── README.md               # This file
└── LICENSE                 # License information

Getting Started

Prerequisites

  • A Unix-based operating system (Linux, macOS, or WSL for Windows).
  • Basic knowledge of terminal commands.
  • Bash shell installed (default on most Unix systems).

Installation

  1. Clone the repository:
    git clone https://github.com/waseemofficial/shell-script-basic.git
    cd shell-script-basic
  2. Make scripts executable:
    chmod +x scripts/*.sh

Usage

  • Backup Script: Automate file backups with compression.
    ./backups/backup.sh /path/to/source /path/to/destination
  • System Monitoring: Monitor CPU and memory usage.
    ./monitoring/system-monitor.sh
  • API Integration: Create GitHub issues from the command line.
    ./api-integration/github-issue.sh "Issue Title" "Issue Description"

🧑‍💻 Example Scripts

1. Backup Script

Automate file backups with compression.

#!/bin/bash
# backup.sh - Automates file backups
SOURCE=$1
DESTINATION=$2
TIMESTAMP=$(date +"%Y%m%d%H%M%S")
tar -czf "${DESTINATION}/backup_${TIMESTAMP}.tar.gz" "$SOURCE"
echo "Backup completed: ${DESTINATION}/backup_${TIMESTAMP}.tar.gz"

Usage:

./backups/backup.sh /path/to/source /path/to/destination

2. System Monitoring

Monitor CPU and memory usage.

#!/bin/bash
# system-monitor.sh - Monitors system resources
echo "CPU Usage: $(top -bn1 | grep load | awk '{printf "%.2f%%\n", $(NF-2)}')"
echo "Memory Usage: $(free -m | awk '/Mem:/ {printf "%.2f%%\n", $3/$2*100}')"

Usage:

./monitoring/system-monitor.sh

3. API Integration

Create GitHub issues from the command line.

#!/bin/bash
# github-issue.sh - Creates a GitHub issue
TITLE=$1
DESCRIPTION=$2
TOKEN="your_github_token"
REPO="your_username/your_repo"

curl -X POST -H "Authorization: token $TOKEN" \
     -d '{"title": "'"$TITLE"'", "body": "'"$DESCRIPTION"'"}' \
     "https://api.github.com/repos/$REPO/issues"

Usage:

./api-integration/github-issue.sh "Issue Title" "Issue Description"

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

  • Special thanks to the open-source community for providing valuable resources and tools.

Contact

For questions or feedback, feel free to reach out:


===

Category Tools/Technologies
Scripting Language Bash (Bourne Again Shell)
Core Utilities grep, awk, sed, find, tar, rsync
Automation cron for task scheduling
Testing BATS (Bash Automated Testing System)
System Monitoring top, free, df, htop
API Integration curl for interacting with REST APIs (e.g., GitHub, Jira)
Version Control Git and GitHub for collaboration

About

This project is designed to help beginners and intermediate users learn and practice shell scripting through a collection of well-documented scripts and examples.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published