πŸ’» 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:

FeatureWhat It Does
--createCreate a new user account
--deleteDelete an existing user
--resetReset password for a user
--listShow all users with UID
--helpShow usage info

🧩 Real-Life Analogy:

TaskReal Life Example
Create UserAdding a new employee to a company
Reset PasswordGiving them a new ID card
Delete UserRemoving them from the system
List UsersViewing 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:

StepCommand
Create backup foldermkdir backup_$(date)
Copy filescp -r source/* backup_folder/
List backupsls -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

CommandUse
readTake user input
if / elseConditional checks
caseMenu-based options
useradd, userdelCreate/Delete users
chpasswdSet passwords
cronSchedule 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

0
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 ✨