Skip to main content

Command Palette

Search for a command to run...

Day 6: Advanced Linux Shell Scripting for DevOps Engineers with User Management

Advanced shell scripting

Published
3 min read
S

"Passionate about simplifying the complexities of DevOps, I bring 5 years of hands-on experience in supporting development and operations teams to achieve faster, more reliable software delivery. I thrive on optimizing CI/CD pipelines, automating workflows, and troubleshooting challenges across diverse cloud environments. My expertise spans across infrastructure management, continuous integration, and performance monitoring—ensuring stability and efficiency at every stage of the software lifecycle. Always eager to learn, collaborate, and innovate, I’m committed to driving impactful change in the DevOps space."

Day 6 focuses on advanced shell scripting techniques specifically for DevOps engineers. The key topic is user management in Linux, which involves:

  • Automating the creation, deletion, and modification of user accounts.

  • Managing groups and permissions.

  • Setting up password policies, expiration, and sudo privileges.

  • Ensuring efficient user access control and security, which is vital for system administration in a DevOps environment.

The goal is to use shell scripting to automate these processes, allowing DevOps engineers to handle user management at scale in a consistent and secure manner.

Task 1: Create Directories Using Shell Script:

Write a bash script createDirectories.sh that, when executed with three arguments (directory name, start number of directories, and end number of directories), creates a specified number of directories with a dynamic directory name.

Example 1: When executed as ./createDirectories.sh day 1 90, it creates 90 directories as day1 day2 day3 ... day90.

Example 2: When executed as ./createDirectories.sh Movie 20 50, it creates 31 directories as Movie20 Movie21 Movie22 ... Movie50.

Solution:

Output:

Movie directory:

Task 2: Create a Script to Backup All Your Work:

Backups are an important part of a DevOps Engineer's day-to-day activities. The video in the references will help you understand how a DevOps Engineer takes backups (it can feel a bit difficult but keep trying, nothing is impossible).

Task 3: Read About Cron and Crontab to Automate the Backup Script:

Cron is the system's main scheduler for running jobs or tasks unattended. A command called crontab allows the user to submit, edit, or delete entries to cron. A crontab file is a user file that holds the scheduling information.

First crontab file:

Taks 4 : Read About User Management:

A user is an entity in a Linux operating system that can manipulate files and perform several other operations. Each user is assigned an ID that is unique within the system. IDs 0 to 999 are assigned to system users, and local user IDs start from 1000 onwards.

  • Create 2 users and display their usernames.

In this post, we explored Advanced Linux Shell Scripting with a focus on user management. From automating user creation, managing groups, setting password policies, to monitoring login activity, these scripts empower DevOps engineers to manage users and permissions efficiently. By automating these tasks, you'll ensure better security, consistency, and scalability in your environments. 💻🔒

🚀 Keep Going!

Mastering these scripting techniques will level up your DevOps game! The more you automate, the smoother your processes will run. Stay curious, keep scripting, and continue your journey toward becoming an expert in Linux for DevOps! ⚡💪

"The DevOps Insight and Learning with Shivani"

Part 18 of 22

"DevOps Insight with Shivani" is a beginner-friendly series exploring DevOps tools, practices, and concepts like CI/CD pipelines. Join me for easy tutorials, practical tips, and industry updates to help you learn and grow in the DevOps world.

Up next

BashBlaze-7-Days-of-Bash-Scripting-Challenge

Day 1: "Mastering the Command Line: Essential Linux Commands for Everyone"

More from this blog

T

The DevOps Insight with Shivani

23 posts