π» DevOps Week 3: Shell Scripting for User Management & Backup Automation


Welcome to Week 3 of the 90DaysOfDevOps β 2025 Edition! This week was all about Shell Scripting β one of the most powerful tools in a DevOps engineerβs toolkit. π§βπ»βοΈ
Letβs break down Linux automation using Bash scripts β for user management, backups, and more β in the simplest way possible!
π§ What is Shell Scripting in DevOps?
Shell scripting allows us to automate repetitive system admin tasks like:
Creating/deleting users
Resetting passwords
Taking backups
Scheduling tasks with
cron
Instead of running 10 commands manually, you can write a script and run it once β saving time and avoiding mistakes. β
π 1. User Account Management Script
Imagine youβre a system admin managing 100s of users. Doing everything manually would be exhausting.
So, I created a script:user_management.sh
β Your personal assistant for account management!
β¨ Features Implemented:
Feature | What It Does |
--create | Create a new user account |
--delete | Delete an existing user |
--reset | Reset password for a user |
--list | Show all users with UID |
--help | Show usage info |
π§© Real-Life Analogy:
Task | Real Life Example |
Create User | Adding a new employee to a company |
Reset Password | Giving them a new ID card |
Delete User | Removing them from the system |
List Users | Viewing employee directory |
π Sample Usage
bashCopyEdit./user_management.sh --create
Output:
pgsqlCopyEditEnter new username: devops_user
Enter password: ******
β
User 'devops_user' created successfully!
π Resetting Password
bashCopyEdit./user_management.sh --reset
pgsqlCopyEditEnter username to reset password: devops_user
Enter new password: ******
π Password for 'devops_user' updated successfully.
π Listing Users
bashCopyEdit./user_management.sh --list
yamlCopyEditUsername: root, UID: 0
Username: devops_user, UID: 1001
Username: ubuntu, UID: 1002
βοΈ 2. Backup with Rotation Script
Next, I created another script:backup_with_rotation.sh
β for safe and automated backups of any directory!
π‘ Why Backups Matter?
If something breaks, a recent backup can save your project, your job, or even your company!
This script:
Creates a timestamped backup
Keeps only the last 3 backups
Can run daily via cron
π§ͺ Example:
bashCopyEdit./backup_with_rotation.sh /home/vaishnavi/documents
Output:
yamlCopyEditβ
Backup created: backup_2025-08-06_13-45-20
ποΈ Deleted old backup: backup_2025-07-31_10-15-00
π§ How It Works:
Step | Command |
Create backup folder | mkdir backup_$(date) |
Copy files | cp -r source/* backup_folder/ |
List backups | ls -dt backup_* |
Keep only 3 | `tail -n +4 |
π Automating with Cron
To run the backup daily at 2:00 AM, I added this line using crontab -e
:
bashCopyEdit0 2 * * * /home/vaishnavi/scripts/backup_with_rotation.sh /home/vaishnavi/documents
Now backups run automatically every day! π₯
π§° 3. Shell Scripting Cheatsheet
Command | Use |
read | Take user input |
if / else | Conditional checks |
case | Menu-based options |
useradd , userdel | Create/Delete users |
chpasswd | Set passwords |
cron | Schedule tasks |
π Summary of Week 3
β
Created CLI tool for Linux user management
β
Automated backups with retention logic
β
Scheduled tasks using cron
β
Practiced writing production-grade Bash scripts
π’ Final Thoughts
Shell scripting is a DevOps superpower. Automate once, save hours forever. π
Whether you're managing users or building CI/CD pipelines β Bash will always be by your side.
π‘ "If you repeat a command more than twice β script it!"
π€ Connect With Me
π Blog Series: https://hashnode.com/@VaishnaviTandekar
π» GitHub Repo: 90DaysOfDevOps
π Hashtags
#90DaysOfDevOps #ShellScripting #Bash #Automation #Linux #Cron #DevOpsBeginner #UserManagement #Backup
Subscribe to my newsletter
Read articles from Vaishnavi Tandekar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Vaishnavi Tandekar
Vaishnavi Tandekar
Hey there! Iβm Vaishnavi π Learning DevOps step by step π οΈ Writing what I learn so no one learns alone β¨