Skip to content

Automation and Some Fun

Summary

This chapter explores ways we can use Linux to Automate our world.

Note that some of this content on PS1 has been covered in previous sections.

Learn to customize your terminal with colorful prompts using PS1 and ANSI color codes, display system information with neofetch, and discover classic Linux easter eggs like cowsay, figlet, and the infamous sl command. A personalized terminal makes daily work more enjoyable.

Concepts Covered

This chapter covers the following concepts from the learning graph:

  1. Automating Tasks
  2. Monitoring Tasks
  3. Logging Tasks
  4. Event Mining
  5. Terminal Customization
  6. Terminal Colors
  7. ANSI Color Codes
  8. Neofetch
  9. Cowsay
  10. Figlet
  11. Sl Command
  12. Linux Easter Eggs

Prerequisites

This chapter builds on concepts from:


Welcome to the Fun Side of Linux!

You've spent a lot of time learning serious Linux skills—file management, permissions, networking, scripting. Now it's time to put those skills to work automatically AND add some personality to your terminal. Because what's the point of mastering Linux if you can't make it look cool and do your work for you while you sleep?

This chapter is split into two parts. First, we'll explore automation—making Linux do repetitive tasks without your constant supervision. Then we'll dive into the fun stuff: making your terminal look amazing and discovering some of the quirky easter eggs that Linux developers have hidden over the years.

Let's automate the boring stuff and beautify the rest!

Part 1: Automation - Let Linux Do the Work

The true power of Linux isn't just doing things—it's doing things automatically. A good sysadmin is a lazy sysadmin (in the best way!). Why manually check disk space every day when a script can do it and alert you only when there's a problem?

Automating Tasks with Cron

Cron is the Linux scheduling system that runs tasks automatically at specified times. The name comes from "chronos" (Greek for time), and it's been helping Linux users automate tasks since the 1970s.

Every Linux system has a cron daemon running in the background, constantly checking if any scheduled tasks need to run. You control it through a "crontab" (cron table)—a file that lists your scheduled tasks.

Viewing and Editing Your Crontab

1
2
3
4
5
6
7
8
# View your current crontab
crontab -l

# Edit your crontab
crontab -e

# Remove your crontab (careful!)
crontab -r

Cron Time Format

Cron uses a specific format for scheduling. Each line in your crontab has five time fields followed by the command:

1
2
3
4
5
6
7
* * * * * command_to_run
│ │ │ │ │
│ │ │ │ └─ Day of week (0-7, 0 and 7 = Sunday)
│ │ │ └─── Month (1-12)
│ │ └───── Day of month (1-31)
│ └─────── Hour (0-23)
└───────── Minute (0-59)

Here are some examples to make it click:

Schedule Cron Expression Meaning
Every minute * * * * * Runs constantly (usually not what you want!)
Every hour 0 * * * * At minute 0 of every hour
Every day at 3 AM 0 3 * * * Perfect for maintenance tasks
Every Monday at 9 AM 0 9 * * 1 Weekly reports
First of month at midnight 0 0 1 * * Monthly tasks
Every 15 minutes */15 * * * * The / means "every"
Weekdays at 8 AM 0 8 * * 1-5 The - defines a range

Practical Cron Examples

Here are some real-world automation examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Backup home directory every night at 2 AM
0 2 * * * tar -czf /backup/home_$(date +\%Y\%m\%d).tar.gz /home/pi

# Clear temp files every Sunday at 4 AM
0 4 * * 0 rm -rf /tmp/*

# Check disk space every hour, email if > 90%
0 * * * * /home/pi/scripts/check_disk.sh

# Update system packages weekly (Sunday at 3 AM)
0 3 * * 0 apt update && apt upgrade -y

# Run a Python script every 5 minutes
*/5 * * * * /usr/bin/python3 /home/pi/scripts/sensor_check.py

Percent Signs in Cron

In crontab, the % character has special meaning (it creates a newline). If you need a literal %, escape it with a backslash: \%. This is why $(date +\%Y\%m\%d) needs backslashes.

Diagram: Cron Scheduling Visualization

Cron Time Field Visualization

Type: microsim

Purpose: Interactive tool to help students understand and build cron expressions

Bloom Taxonomy: Apply (L3)

Learning Objective: Students will construct valid cron expressions by manipulating time fields

Canvas layout (800x500): - Top section: Five dropdowns/input fields for cron time fields - Middle section: Human-readable interpretation of the schedule - Bottom section: Preview of next 5 scheduled run times

Visual elements: - Five columns representing minute, hour, day, month, day-of-week - Each column shows current value with up/down arrows - Color coding: green for valid, red for invalid entries - Clock face showing when task will run - Calendar preview showing dates for monthly patterns

Interactive controls: - Dropdown or spinner for each time field - Quick preset buttons: "Daily at midnight", "Every hour", "Weekly", "Every 5 minutes" - Text input for direct cron expression entry - "Copy to clipboard" button

Default parameters: - Expression: 0 * * * * (every hour) - Shows next 5 runs based on current time

Behavior: - Real-time update of human-readable text as fields change - Highlight invalid combinations (e.g., day 31 in February) - Show warning for very frequent schedules - Calculate and display next run times

Implementation: p5.js with date/time calculation library

Monitoring Tasks

Setting up automation is only half the battle—you also need to know if your tasks are actually running! Monitoring ensures your automated systems are working correctly.

Checking Cron Logs

Cron logs its activities to the system log. Here's how to see what's been happening:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# View cron logs (Debian/Ubuntu/Raspberry Pi OS)
grep CRON /var/log/syslog

# Recent cron activity
grep CRON /var/log/syslog | tail -20

# Watch cron logs in real-time
tail -f /var/log/syslog | grep CRON

# On some systems, cron has its own log
cat /var/log/cron.log

Creating a Monitoring Script

Let's create a simple monitoring script that checks if your important services are running:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#!/bin/bash
# save as /home/pi/scripts/service_monitor.sh

SERVICES="ssh nginx cron"
LOG_FILE="/var/log/service_monitor.log"

for service in $SERVICES; do
    if systemctl is-active --quiet "$service"; then
        echo "$(date): $service is running" >> "$LOG_FILE"
    else
        echo "$(date): WARNING - $service is NOT running!" >> "$LOG_FILE"
        # Could add email alert here
    fi
done

Then schedule it to run every 10 minutes:

1
*/10 * * * * /home/pi/scripts/service_monitor.sh

Logging Tasks

Good logging is essential for debugging automation issues. When something goes wrong at 3 AM, logs are your best friend for figuring out what happened.

Redirecting Output to Logs

Every cron job should log its output:

1
2
3
4
5
# Log stdout to a file
0 * * * * /home/pi/scripts/backup.sh >> /var/log/backup.log 2>&1

# The 2>&1 redirects errors (stderr) to the same file as stdout
# This captures EVERYTHING your script outputs

Using the logger Command

The logger command writes messages to the system log (syslog), which is the proper place for system messages:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Basic logging
logger "Backup script started"

# With priority/severity
logger -p user.info "Backup completed successfully"
logger -p user.error "Backup FAILED!"

# With a tag for easy filtering
logger -t backup "Starting nightly backup"

# Then search with:
grep backup /var/log/syslog

Creating Professional Log Entries

Here's a pattern for logging in your scripts:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
# Professional logging example

SCRIPT_NAME="backup_script"
LOG_TAG="[$SCRIPT_NAME]"

log_info() {
    logger -t "$SCRIPT_NAME" -p user.info "$1"
    echo "$(date '+%Y-%m-%d %H:%M:%S') INFO: $1"
}

log_error() {
    logger -t "$SCRIPT_NAME" -p user.error "$1"
    echo "$(date '+%Y-%m-%d %H:%M:%S') ERROR: $1" >&2
}

# Usage in script:
log_info "Starting backup process"
if [ $? -eq 0 ]; then
    log_info "Backup completed successfully"
else
    log_error "Backup failed with exit code $?"
fi

Event Mining: Finding Patterns in Logs

Event mining is the art of analyzing logs to find patterns, problems, and insights. With all those log files accumulating, how do you find what matters?

Basic Log Analysis

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Count occurrences of specific errors
grep -c "ERROR" /var/log/syslog

# Find unique IP addresses in web logs
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -10

# Find failed SSH login attempts
grep "Failed password" /var/log/auth.log

# Count events by hour
awk '{print $3}' /var/log/syslog | cut -d: -f1 | sort | uniq -c

Using journalctl for Systemd Logs

Modern Linux systems use systemd and journalctl for centralized logging:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# View all logs (most recent)
journalctl -e

# Logs from the current boot
journalctl -b

# Logs from a specific service
journalctl -u nginx

# Logs from the last hour
journalctl --since "1 hour ago"

# Follow logs in real-time (like tail -f)
journalctl -f

# Show only errors and above
journalctl -p err

# JSON output for scripting
journalctl -o json-pretty | head -50

Diagram: Log Analysis Workflow

Log Analysis and Event Mining Workflow

Type: workflow

Purpose: Show the process of analyzing logs to find actionable insights

Bloom Taxonomy: Analyze (L4)

Learning Objective: Students will analyze the log analysis workflow and understand how to extract meaningful patterns

Visual style: Flowchart with decision points

Steps: 1. Start: "Logs Generated" Hover text: "Applications, services, and system generate log entries"

  1. Process: "Collect Logs" Hover text: "Centralize logs using syslog, journald, or log aggregators"

  2. Process: "Filter by Severity" Hover text: "Focus on errors, warnings first: journalctl -p warning"

  3. Decision: "Known Pattern?" Hover text: "Does this match a known issue or expected behavior?"

5a. Process: "Auto-Alert" (if known critical) Hover text: "Send notification for known critical patterns"

5b. Process: "Investigate" (if unknown) Hover text: "Use grep, awk, and analysis tools to understand"

  1. Process: "Extract Patterns" Hover text: "Use awk, sort, uniq to find common occurrences"

  2. Process: "Correlate Events" Hover text: "Match timestamps across different log sources"

  3. Process: "Document Findings" Hover text: "Record what you learned for future reference"

  4. Decision: "Action Needed?" Hover text: "Does this require intervention?"

10a. Process: "Create Fix/Alert" (if yes) Hover text: "Implement solution or create monitoring rule"

10b. End: "Archive for Reference" (if no) Hover text: "Keep for historical analysis"

Color coding: - Blue: Data collection steps - Yellow: Decision points - Green: Analysis steps - Orange: Action steps

Implementation: Mermaid flowchart or HTML/CSS/JS workflow

Creating Automated Alerts

Here's a script that monitors logs and sends alerts when it finds problems:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
# save as /home/pi/scripts/log_watcher.sh

ALERT_PATTERNS=(
    "Out of memory"
    "disk full"
    "Connection refused"
    "Permission denied"
)

LOG_FILE="/var/log/syslog"
ALERT_LOG="/var/log/alerts.log"

for pattern in "${ALERT_PATTERNS[@]}"; do
    count=$(grep -c "$pattern" "$LOG_FILE" 2>/dev/null)
    if [ "$count" -gt 0 ]; then
        echo "$(date): ALERT - Found $count instances of '$pattern'" >> "$ALERT_LOG"
        # Could send email or notification here
    fi
done

Part 2: Making Your Terminal Beautiful (and Weird)

Now for the fun part! Let's transform your boring terminal into something that reflects your personality. This isn't just about looking cool—a well-customized terminal can also be more informative and easier to use.

Terminal Customization Basics

Your terminal's appearance is controlled by several factors:

  • PS1: The prompt string (what appears before your cursor)
  • Colors: ANSI escape codes for text and background colors
  • Terminal emulator settings: Font, window size, transparency
  • Shell configuration: ~/.bashrc or ~/.zshrc files

Understanding ANSI Color Codes

ANSI escape codes are special character sequences that control terminal appearance. They might look like magic (or gibberish), but they follow a predictable pattern.

The basic format is:

1
\e[CODEm or \033[CODEm

Where:

  • \e or \033 = The escape character
  • [ = Start of the control sequence
  • CODE = One or more numbers (separated by ;)
  • m = End of the control sequence

Color Codes Quick Reference

Code Effect Code Effect
0 Reset all 1 Bold
30 Black text 40 Black background
31 Red text 41 Red background
32 Green text 42 Green background
33 Yellow text 43 Yellow background
34 Blue text 44 Blue background
35 Magenta text 45 Magenta background
36 Cyan text 46 Cyan background
37 White text 47 White background

You can combine codes with semicolons:

1
2
3
4
5
6
7
8
# Bold red text
echo -e "\e[1;31mBold Red\e[0m"

# Green text on white background
echo -e "\e[32;47mGreen on White\e[0m"

# Bold blue text, then reset
echo -e "\e[1;34mBold Blue\e[0m Normal"

Always end with \e[0m to reset colors, or everything after will be affected!

Diagram: ANSI Color Code Chart

ANSI Color Code Interactive Reference

Type: microsim

Purpose: Interactive color picker showing ANSI codes and live preview

Bloom Taxonomy: Apply (L3)

Learning Objective: Students will apply ANSI color codes to create custom terminal colors

Canvas layout (800x500): - Left side (400px): Color palette grid - Right side (400px): Preview area and code output

Visual elements: - 8x2 grid for standard colors (text and background) - 8x2 grid for bright/bold variants - Large preview box showing sample text - Code output area with copyable text

Color grid: - Row 1: Standard foreground colors (30-37) - Row 2: Standard background colors (40-47) - Row 3: Bright foreground colors (90-97) - Row 4: Bright background colors (100-107)

Interactive controls: - Click color to select foreground - Shift+click to select background - Checkbox: Bold - Checkbox: Underline - Checkbox: Italic - Text input: Sample text to display - Button: "Copy Code"

Preview area: - Shows sample text with selected styling - Updates in real-time - Dark background option toggle

Output formats: - Echo command: echo -e "\e[1;31mText\e[0m" - PS1 format: [\e[1;31m]Text[\e[0m] - Bash variable: RED='\e[31m'

Default: - No selection (white text, no background) - Sample text: "Hello, Linux!"

Implementation: p5.js with clipboard API

Terminal Colors in Practice

Let's put those color codes to use:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Add these to your ~/.bashrc for easy access

# Color definitions
RED='\e[31m'
GREEN='\e[32m'
YELLOW='\e[33m'
BLUE='\e[34m'
MAGENTA='\e[35m'
CYAN='\e[36m'
BOLD='\e[1m'
RESET='\e[0m'

# Colorful aliases
alias ls='ls --color=auto'
alias grep='grep --color=auto'

# Custom colorful messages
success() {
    echo -e "${GREEN}$1${RESET}"
}

error() {
    echo -e "${RED}$1${RESET}"
}

warning() {
    echo -e "${YELLOW}$1${RESET}"
}

# Usage:
# success "Operation completed!"
# error "Something went wrong"
# warning "Proceed with caution"

Customizing PS1 (Your Prompt)

The PS1 variable defines what your prompt looks like. By default, it's probably something boring like user@hostname:~$. Let's make it awesome!

PS1 Special Characters

Code Meaning
\u Username
\h Hostname (short)
\H Hostname (full)
\w Current directory (full path)
\W Current directory (basename only)
\d Date
\t Time (24-hour)
\T Time (12-hour)
\n Newline
\$ $ for regular user, # for root

PS1 Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Simple colored prompt
PS1='\[\e[32m\]\u@\h\[\e[0m\]:\[\e[34m\]\w\[\e[0m\]\$ '

# With time
PS1='[\t] \[\e[32m\]\u\[\e[0m\]:\[\e[34m\]\W\[\e[0m\]\$ '

# Two-line prompt with full path
PS1='\[\e[36m\]┌──(\[\e[1;32m\]\u@\h\[\e[36m\])-[\[\e[1;34m\]\w\[\e[36m\]]\n\[\e[36m\]└─\[\e[1;32m\]\$\[\e[0m\] '

# Emoji prompt (if your terminal supports Unicode)
PS1='🐧 \[\e[32m\]\u\[\e[0m\] in \[\e[34m\]\W\[\e[0m\] \$ '

# Git-aware prompt (shows branch name)
parse_git_branch() {
    git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
PS1='\[\e[32m\]\u\[\e[0m\]:\[\e[34m\]\W\[\e[33m\]$(parse_git_branch)\[\e[0m\]\$ '

Testing PS1 Changes

Before adding a PS1 to your ~/.bashrc, test it by typing PS1='your_prompt_here' directly in the terminal. If something goes wrong, just close the terminal and open a new one!

Neofetch: System Info in Style

Neofetch displays system information alongside ASCII art of your distro's logo. It's perfect for screenshots and showing off your setup!

1
2
3
4
5
# Install neofetch
sudo apt install neofetch

# Run it
neofetch

You'll see something beautiful like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
       _,met$$$$$gg.          pi@raspberrypi
    ,g$$$$$$$$$$$$$$$P.       ---------------
  ,g$$P"     """Y$$.".        OS: Raspbian GNU/Linux 11 armv7l
 ,$$P'              `$$$.     Host: Raspberry Pi 4 Model B Rev 1.4
',$$P       ,ggs.     `$$b:   Kernel: 6.1.21-v7l+
`d$$'     ,$P"'   .    $$$    Uptime: 3 days, 14 hours
 $$P      d$'     ,    $$P    Packages: 1423 (dpkg)
 $$:      $$.   -    ,d$$'    Shell: bash 5.1.4
 $$;      Y$b._   _,d$P'      Resolution: 1920x1080
 Y$$.    `.`"Y$$$$P"'         Terminal: /dev/pts/0
 `$$b      "-.__              CPU: BCM2711 (4) @ 1.800GHz
  `Y$$                        Memory: 412MiB / 3791MiB
   `Y$$.
     `$$b.
       `Y$$b.
          `"Y$b._
              `"""

Neofetch Configuration

Neofetch is highly customizable. The config file is at ~/.config/neofetch/config.conf.

1
2
3
4
5
6
7
8
# Create config directory if it doesn't exist
mkdir -p ~/.config/neofetch

# Copy default config
neofetch --print_config > ~/.config/neofetch/config.conf

# Edit to customize
nano ~/.config/neofetch/config.conf

Popular customizations:

  • Change the ASCII art to a different distro or custom image
  • Add/remove information fields
  • Change colors
  • Add custom ASCII art
1
2
3
4
5
6
7
8
# Run with a different ASCII logo
neofetch --ascii_distro ubuntu

# Use a custom image (requires w3m or kitty terminal)
neofetch --source /path/to/image.png

# Add to ~/.bashrc to run on terminal open
echo 'neofetch' >> ~/.bashrc

Cowsay: Because Why Not?

Cowsay makes a cow (or other creature) say whatever you want. It's completely useless and absolutely delightful.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Install cowsay
sudo apt install cowsay

# Basic usage
cowsay "Hello, Linux!"

# Output:
 _______________
< Hello, Linux! >
 ---------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Different Cowsay Characters

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# See all available characters
cowsay -l

# Use different characters
cowsay -f tux "Linux is awesome!"      # Tux the penguin!
cowsay -f dragon "Fear me!"            # A dragon
cowsay -f bunny "Hop hop!"             # A bunny
cowsay -f ghostbusters "Who ya gonna call?"

# Cowthink (thought bubble instead of speech)
cowthink "Hmm, interesting..."

Cowsay + Fortune = Magic

1
2
3
4
5
6
7
8
# Install fortune
sudo apt install fortune-mod

# Combine them for random wisdom from animals
fortune | cowsay

# Add to ~/.bashrc for daily wisdom
echo 'fortune | cowsay -f $(ls /usr/share/cowsay/cows/ | shuf -n 1)' >> ~/.bashrc

Figlet: Big ASCII Text

Figlet creates large ASCII art text banners. Great for scripts, welcome messages, or just fun.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Install figlet
sudo apt install figlet

# Basic usage
figlet "Hello"

# Output:
 _   _      _ _
| | | | ___| | | ___
| |_| |/ _ \ | |/ _ \
|  _  |  __/ | | (_) |
|_| |_|\___|_|_|\___/

Figlet Fonts

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# List available fonts
ls /usr/share/figlet/

# Use different fonts
figlet -f slant "Linux"
figlet -f banner "Cool"
figlet -f small "Compact"
figlet -f big "BIG"

# Install more fonts
sudo apt install figlet-fonts

# Center the text
figlet -c "Centered"

# Set width
figlet -w 60 "Wrapped Text"

Combining Tools

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Colorful figlet
figlet "Linux" | lolcat    # Requires: sudo apt install lolcat

# System welcome banner
#!/bin/bash
echo -e "\e[34m"
figlet -f slant "Welcome"
echo -e "\e[32m"
echo "Today is $(date '+%A, %B %d, %Y')"
echo "Uptime: $(uptime -p)"
echo -e "\e[0m"

The Infamous sl Command

Here's a Linux easter egg with a lesson: the sl command. Most people have accidentally typed sl when they meant ls. Instead of an error, this package rewards (punishes?) you with a steam locomotive chugging across your terminal!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Install sl
sudo apt install sl

# "Accidentally" type it
sl

# Watch in horror as a train slowly crosses your screen
# You can't stop it! (Well, Ctrl+C works, but where's the fun?)

# Options:
sl -l    # Little train
sl -a    # An accident occurs (people scream for help)
sl -F    # Flying train
sl -e    # Allow Ctrl+C to stop it (for the impatient)

The creator made sl because he kept mistyping ls and wanted to train himself to be more careful. The punishment of waiting for a train to cross your screen is surprisingly effective!

More Linux Easter Eggs

The Linux and UNIX world is full of fun surprises hidden by developers with a sense of humor:

apt moo

1
2
apt moo
# Have you mooed today?

Yes Command (Kind of Useless, Entirely Fun)

1
2
3
4
5
6
7
8
# Prints "y" forever (useful for scripts, amusing otherwise)
yes

# Custom message
yes "Linux is awesome"

# Useful: Auto-confirm installations
yes | sudo apt install package

Rev (Reverse Text)

1
2
3
4
5
echo "Hello World" | rev
# dlroW olleH

# Reverse a file
rev filename.txt

Factor (Prime Factorization)

1
2
3
4
5
factor 42
# 42: 2 3 7

factor 1234567890
# 1234567890: 2 3 3 5 3607 3803
Linux Easter Eggs Interactive Gallery

Type: infographic

Purpose: Showcase various Linux easter eggs and fun commands with live examples

Bloom Taxonomy: Remember (L1)

Learning Objective: Students will recall various Linux easter eggs and fun commands

Layout: Gallery grid with clickable cards

Cards (each shows command and preview):

  1. sl - Steam Locomotive
  2. Preview: ASCII train animation
  3. Command: sl
  4. Fun fact: Created to punish typos

  5. cowsay - Talking Cow

  6. Preview: Cow with speech bubble
  7. Command: cowsay "message"
  8. Variations: -f tux, -f dragon

  9. figlet - ASCII Banners

  10. Preview: Large text example
  11. Command: figlet "text"
  12. Fonts: slant, banner, small

  13. fortune - Random Quotes

  14. Preview: Sample fortune
  15. Command: fortune
  16. Combine: fortune | cowsay

  17. cmatrix - Matrix Effect

  18. Preview: Green falling characters
  19. Command: cmatrix
  20. Install: sudo apt install cmatrix

  21. lolcat - Rainbow Text

  22. Preview: Colorful gradient text
  23. Command: echo "text" | lolcat
  24. Animate: lolcat -a

  25. asciiquarium - Fish Tank

  26. Preview: ASCII fish swimming
  27. Command: asciiquarium
  28. Install: separate package

  29. apt moo - Hidden Cow

  30. Preview: Super cow powers
  31. Command: apt moo
  32. Easter egg!

Interactive features: - Click card to see live terminal output - Copy command button - Install instructions for each

Color scheme: Dark terminal theme with syntax highlighting

Implementation: HTML/CSS grid with animated previews

Creating Your Own Welcome Script

Let's combine everything we've learned to create an awesome terminal welcome script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# save as ~/.welcome.sh

# Colors
RED='\e[31m'
GREEN='\e[32m'
YELLOW='\e[33m'
BLUE='\e[34m'
CYAN='\e[36m'
RESET='\e[0m'

clear

# Header
echo -e "${CYAN}"
figlet -f slant "Welcome!"
echo -e "${RESET}"

# System info
echo -e "${GREEN}═══════════════════════════════════════════${RESET}"
echo -e "${YELLOW}User:${RESET} $(whoami)@$(hostname)"
echo -e "${YELLOW}Date:${RESET} $(date '+%A, %B %d, %Y')"
echo -e "${YELLOW}Time:${RESET} $(date '+%H:%M:%S')"
echo -e "${YELLOW}Uptime:${RESET} $(uptime -p)"
echo -e "${YELLOW}Memory:${RESET} $(free -h | awk '/^Mem:/ {print $3 "/" $2}')"
echo -e "${YELLOW}Disk:${RESET} $(df -h / | awk 'NR==2 {print $3 "/" $2 " (" $5 " used)"}')"
echo -e "${GREEN}═══════════════════════════════════════════${RESET}"

# Random quote
echo ""
fortune | cowsay -f tux

echo ""

Add to your ~/.bashrc:

1
2
3
4
# Run welcome script
if [ -f ~/.welcome.sh ]; then
    bash ~/.welcome.sh
fi

Key Takeaways

You've learned how to make Linux work for you AND look good doing it! Here's what you can now do:

Automation:

  • Schedule tasks with cron using the five-field time format
  • Monitor scheduled tasks and check cron logs
  • Create professional logging in your scripts
  • Mine logs for patterns and create automated alerts

Terminal Fun:

  • Use ANSI color codes to add color to terminal output
  • Customize your prompt (PS1) with colors and information
  • Display system info beautifully with neofetch
  • Make animals talk with cowsay
  • Create ASCII banners with figlet
  • Appreciate the humor of Linux easter eggs like sl

The Bigger Picture:

  • Automation saves time and reduces human error
  • Good logging makes debugging much easier
  • A personalized terminal makes daily work more enjoyable
  • The Linux community has a great sense of humor!

Practice Exercises

Exercise 1: Create a Backup Cron Job

Set up a cron job that: - Runs every day at 2:30 AM - Creates a compressed backup of your home directory - Logs the start and end time to /var/log/backup.log - Only keeps backups from the last 7 days

Hint: You'll need to combine cron, tar, find (for cleanup), and logging.

Exercise 2: Build a Custom PS1

Create a PS1 prompt that includes: - Your username in green - The current time in cyan - The current directory in blue - The git branch (if in a git repo) in yellow - A $ on a new line

Hint: Use the PS1 special characters and the parse_git_branch function from the chapter.

Exercise 3: Log Analysis Script

Write a script that analyzes /var/log/syslog and produces a report showing: - Total number of log entries - Breakdown by log level (error, warning, info) - Top 5 most frequent processes writing logs - Any entries containing "fail" or "error"

Hint: Use grep, awk, sort, and uniq.

Exercise 4: Ultimate Welcome Script

Create a welcome script that: - Shows a colorful figlet banner with your name - Displays system stats (CPU temp if on Pi, memory, disk) - Shows the weather for your location (use curl wttr.in) - Ends with a random fortune from a talking Tux

Hint: Combine everything from this chapter!


Remember: A great Linux user doesn't just know the commands—they make the system work for them. Automate the boring stuff, beautify the rest, and never forget that a steam locomotive might be just one typo away! 🚂

References

  1. Crontab Guru - Cron Schedule Expression Editor - Interactive tool for creating and understanding cron expressions with examples and explanations.

  2. Linux Handbook - Complete Guide to Cron Jobs - Comprehensive tutorial on scheduling tasks, cron syntax, and automation best practices.

  3. DigitalOcean - How To Use Cron To Automate Tasks - Step-by-step guide to creating, editing, and troubleshooting cron jobs.

  4. journalctl Tutorial - Complete guide to viewing and analyzing systemd logs using journalctl commands.

  5. The Art of Command Line - Customization Section - GitHub guide covering terminal customization, ANSI colors, and productivity tools.

  6. ANSI Escape Codes Reference - Comprehensive reference for terminal color codes and text formatting.

  7. Bash Prompt HOWTO - Detailed guide to customizing PS1 prompts with colors, special characters, and dynamic information.

  8. Neofetch GitHub Repository - Official documentation and customization guide for the Neofetch system information tool.

  9. Linux Journal - Shell Scripting and Automation - Articles on writing effective automation scripts and monitoring solutions.

  10. GeeksforGeeks - Linux Automation - Educational tutorials on cron jobs, task scheduling, and automation techniques.

  11. Cowsay and Fortune Documentation - Guide to using cowsay with different characters and combining with fortune for random messages.

  12. Figlet Official Documentation - Complete reference for creating ASCII art text banners with different fonts and styles.

  13. Red Hat - Log Analysis Best Practices - Professional techniques for mining logs, finding patterns, and troubleshooting issues.

  14. TecMint - 20 Useful Terminal Customization Tips - Practical guide to making your terminal beautiful and functional.

  15. Linux Foundation - Automation and Scripting Course - Free resources on task automation and monitoring.

  16. Opensource.com - Automation Tutorials - Community articles on cron jobs, shell scripts, and Linux automation strategies.

  17. lolcat GitHub Repository - Documentation for the rainbow colorization tool with usage examples and installation instructions.

  18. Linux Journey - Logging and Monitoring - Interactive lessons on syslog, journald, and log analysis techniques.

  19. Bash Scripting Tutorial - Automation - Step-by-step guide to writing scripts for task automation and system monitoring.

  20. LinuxConfig - Scheduled Tasks and Automation - Practical examples of automating backups, updates, and system maintenance.