Advanced Linux Shell Scripting for DevOps Engineers with User Management

Nitin DhimanNitin Dhiman
2 min read

As part of my continuous learning journey in DevOps, I delved into advanced Linux shell scripting and user management. These skills are essential for automating repetitive tasks and managing user access, which are crucial for any DevOps engineer.

Before diving into advanced topics, you might want to check out my previous blog post on Basic Linux Shell Scripting for DevOps Engineers to ensure you have a solid foundation.

In this blog we have some task to perform on Advanced Linux Shell Scripting.

Task 1: Creating Multiple Directories Dynamically

Creating multiple directories manually can be time-consuming and error-prone. Instead, I wrote a shell script that uses loops and arguments to create a specified number of directories with dynamic names. Here’s how you can do it:

To run this script, use:

bash <filename>.sh Movie 20 50

This will create directories named Movie20 to Movie50. in one go.

Task 2: Backup Script

Backups are an essential part of a DevOps engineer’s routine to ensure data protection. I created a script to back up all my work done so far. This script copies the contents of a specified source directory to a backup directory.

Task 3: Automating Backups with Cron:

To automate the backup process, I used Cron and Crontab. Cron is the system’s main scheduler for running jobs or tasks unattended. Here’s how to set up a Cron job for the backup script:

  1. Open the Crontab editor:
crontab -e
  1. Add a new Cron job:
0 2 * * * /path/to/backupScript.sh

This Cron job runs the backup script every day at 2 AM.

I will write a complete blog post on using crontab.

Task 4: User Management

User management is fundamental for Linux administration. In this task, I created two users and displayed their usernames.

Creating Users:

sudo useradd Nitin1
sudo useradd Nitin2

Displaying Usernames:

cut -d: -f1 /etc/passwd | tail -n 2

This command lists the last two usernames added to the system.

0
Subscribe to my newsletter

Read articles from Nitin Dhiman directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nitin Dhiman
Nitin Dhiman