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.
- 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.
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
, andtar
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
andawk
for pattern matching and data extraction. - System Monitoring: Scripts for monitoring CPU, memory, and disk usage using commands like
top
,free
, anddf
. - File Management: Examples include backup scripts, log rotation, and file synchronization using
rsync
andtar
. - APIs and Integration: Scripts demonstrate interaction with APIs (e.g., GitHub, Jira) using
curl
.
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
- A Unix-based operating system (Linux, macOS, or WSL for Windows).
- Basic knowledge of terminal commands.
- Bash shell installed (default on most Unix systems).
- Clone the repository:
git clone https://github.com/waseemofficial/shell-script-basic.git cd shell-script-basic
- Make scripts executable:
chmod +x scripts/*.sh
- 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"
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
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
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"
This project is licensed under the MIT License. See the LICENSE file for details.
- Special thanks to the open-source community for providing valuable resources and tools.
For questions or feedback, feel free to reach out:
- GitHub: waseemofficial
- Email Me via Gmail:
===
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 |