Skip to content

boraderohan/Shell-Scripts

Repository files navigation

Shell Scripting Learning Project

A comprehensive collection of bash scripts demonstrating fundamental to intermediate shell scripting concepts, from basic scripts to production-ready maintenance automation.

1. Shell Scripting Basics

Scripts covering foundational bash concepts.

hello.sh

  • Purpose: First shell script introduction
  • Concepts: Shebang line, echo command, script execution
  • Key Learning: Scripts require shebang (#!/bin/bash) and executable permissions

variables.sh

  • Purpose: Demonstrate variable usage and quoting differences
  • Concepts: Variable assignment, single vs. double quotes, variable expansion
  • Key Learning: Double quotes allow variable expansion; single quotes treat content literally

greet.sh

  • Purpose: User input handling with the read command
  • Concepts: read command, user prompts, variable interpolation
  • Key Learning: Collect user input and use it in output messages

check_number.sh

  • Purpose: Conditional logic with if-else statements
  • Concepts: Numeric comparisons (-gt, -lt), if-elif-else structures
  • Key Learning: Evaluate numbers and branch logic based on conditions

file_check.sh

  • Purpose: File existence validation
  • Concepts: File test operators (-f), conditional execution
  • Key Learning: Check if files exist before processing them

server_check.sh

  • Purpose: Service status monitoring with user interaction
  • Concepts: Variables, conditionals, systemctl command integration
  • Key Learning: Combine user input with system commands for automation

2. Shell Scripting: Loops, Arguments & Error Handling

Scripts demonstrating control flow and robust script design.

for_loop.sh

  • Purpose: Iterate through arrays using for loops
  • Concepts: Array definition, for-in loops, array expansion
  • Key Learning: Loop through collections efficiently

count.sh

  • Purpose: Print numbers 1-10 using C-style for loops
  • Concepts: C-style for loop syntax, numeric iteration
  • Key Learning: Alternative loop syntax for numeric ranges

countdown.sh

  • Purpose: Countdown timer using while loops
  • Concepts: While loops, variable arithmetic, sleep command
  • Key Learning: While loops for condition-based iteration

greets.sh

  • Purpose: Accept command-line arguments
  • Concepts: $1 positional argument, argument validation, usage messages
  • Key Learning: Pass data to scripts via command line

args_demo.sh

  • Purpose: Demonstrate all argument variables
  • Concepts: $# (argument count), $@ (all arguments), $0 (script name)
  • Key Learning: Access and use command-line arguments

install_packages.sh

  • Purpose: Automated package installation with status checking
  • Concepts: Loops, package manager integration (apt-get), conditional installation
  • Key Learning: Automate system administration tasks

safe_script.sh

  • Purpose: Error handling best practices
  • Concepts: set -e (exit on error), || operator for error handling
  • Key Learning: Make scripts fail safely and predictably

3. Shell Scripting: Functions & Intermediate Concepts

Scripts showcasing modular design and advanced techniques.

functions.sh

  • Purpose: Basic function definition and calling
  • Concepts: Function syntax, function calls, local variables
  • Key Learning: Functions make scripts modular and reusable

disk_check.sh

  • Purpose: System resource monitoring with functions
  • Concepts: Functions with specific purposes, df and free commands, main function pattern
  • Key Learning: Organize scripts with dedicated functions for each task

strict_demo.sh

  • Purpose: Demonstrate strict mode options
  • Concepts: set -e, set -u, set -o pipefail
  • Key Learning: Use strict mode flags to catch errors early

local_demo.sh

  • Purpose: Local vs. global variable scope
  • Concepts: local keyword, variable scope, function isolation
  • Key Learning: Local variables prevent variable leakage between functions

system_info.sh

  • Purpose: Comprehensive system information reporter
  • Concepts: Multiple functions, command substitution, output formatting
  • Key Learning: Combine multiple functions for complex reporting tasks

4. Shell Scripting Project: Log Rotation, Backup & Crontab

Production-ready scripts for server maintenance automation.

log_rotate.sh

  • Purpose: Automated log file management
  • Concepts: find command, gzip compression, file deletion, timestamps
  • Key Learning: Compress logs older than 7 days; delete .gz files older than 30 days
  • Usage: `./log_rotate

About

This repository includes the scripts which was written in assignments from day-16 to day-21

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors