Day 5 of #90DaysOfDevOps:


Advanced Linux Shell Scripting + User Management
Have you ever wondered how DevOps engineers handle repetitive tasks like creating 90 folders or backing up large directories โ without typing 90 commands?
Let me show you how Linux Shell Scripting, Cron jobs, and a few simple commands can automate hours of work in seconds.
๐ง Challenge 1: Create 90 Directories Instantly
When you open the 2023
folder in the DevOps repository and notice 90 sub-directories โ what do you think?
Were they created manually?
Nope. They were created in 1 second using:
mkdir day{1..90}
Just like that, 90 folders. One command. ๐ฅ
Thatโs the power of Bash and Shell Scripting.
โ๏ธ Task 1: createDirectories.sh
โ A Dynamic Directory Generator
Letโs create a reusable script that can generate any number of directories with custom names.
๐ ๏ธ Script: createDirectories.sh
#!/bin/bash
# Check if arguments are passed
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <DirectoryName> <StartNumber> <EndNumber>"
exit 1
fi
prefix=$1
start=$2
end=$3
for i in $(seq $start $end)
do
mkdir "${prefix}${i}"
done
๐ How to Use:
chmod +x createDirectories.sh
# Example 1:
./createDirectories.sh day 1 90
# Creates day1 day2 ... day90
# Example 2:
./createDirectories.sh Movie 20 50
# Creates Movie20 Movie21 ... Movie50
Simple, dynamic, and fast. ๐โโ๏ธ๐จ
๐ Task 2: Automating Your Backups with a Script
As a DevOps engineer, backups are your safety net.
Hereโs how you can write a quick backup script that compresses your code, logs, or entire directory into a .tar.gz
file.
๐ ๏ธ backup.sh
Script
#!/bin/bash
# Backup directory
source_dir="/home/yourname/projects"
backup_dir="/home/yourname/backups"
# Create backup directory if it doesn't exist
mkdir -p "$backup_dir"
# Create archive
tar -czf "$backup_dir/project_backup_$(date +%F).tar.gz" "$source_dir"
echo "Backup completed at $(date)"
Replace paths with your local setup. โ
๐ Task 3: Automate Backup with cron
Crontab lets you run the backup script on a schedule. To open the crontab editor:
crontab -e
To run the backup daily at 10 PM:
0 22 * * * /home/yourname/backup.sh
Cron syntax can be tricky, but once you get it โ you automate everything.
๐ค Task 4: User Management in Linux
DevOps = automation + security.
So you must know how to manage users in a Linux system.
๐ Commands to Create & Manage Users:
# Create users
sudo useradd user1
sudo useradd user2
# Set passwords
sudo passwd user1
sudo passwd user2
# Display usernames
cut -d: -f1 /etc/passwd | grep user
๐ง System users = UID 0โ999
๐ค Normal users = UID 1000+
User management = Access control, security, and scripting power ๐ช
๐ก What I Learned Today:
You donโt need to repeat anything manually in Linux โ write a script and let it fly.
Backups are not optional in DevOps โ theyโre mission-critical.
Cron is like your invisible assistant, automating everything silently.
User management is the foundation of permission control in Linux.
๐บ Final Thoughts
Shell scripting is one of the most underrated superpowers in DevOps.
It saves time, improves consistency, and prepares you for automation at scale.
Today's tasks may look simple, but they lay the foundation for real-world DevOps workflows.
Subscribe to my newsletter
Read articles from Mayuresh Patil directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Mayuresh Patil
Mayuresh Patil
Hi, I am an Aspiring DevOps Engineer and Python Enthusiast who was actively learning new skills which will maximize my knowledge.