Advanced Linux Shell Scripting for DevOps Engineers with User management

Advanced Linux Shell Scripting for DevOps Engineers with User management

·

3 min read

In the world of DevOps, knowing how to use Linux commands effectively is super important. Let’s learn some tricks to make our work easier. This will not only automate repetitive tasks but also enables to manage users and permissions effectively, contributing to a more secure and organized environment.

Write a bash script create directories.sh that when the script is executed with three given arguments (one is the directory name and second is start number of directories and third is the end number of directories ) it creates a specified number of directories with a dynamic directory name.

Example 1: When the script is executed as./createDirectories.sh day 1 90 then it creates 90 directories as day1 day2 day3 .... day90

Here's is the script

After executing the script it will give Day1…. Day90 directories.

Example 2: When the script is executed as ./createDirectories.sh Movie 20 50 then it creates 50 directories as Movie20 Movie21 Movie23 ...Movie50

  1. Create a Script to backup all your work done till now.

Backups are an important part of DevOps Engineer's day to Day activities The video in References will help you to understand How a DevOps Engineer takes backups

  1. Cron is a time-based job scheduler in linux operating systems. It helps you schedule tasks to happen automatically at certain times.

Crontab is where you write down these schedules in a file. So, if you want to back up your files regularly without having to remember to do it yourself, you can use Cron and Crontab to set it up. It's like having a little helper that does the work for you on a schedule you decide.

crontab -e: This command is used to edit the user's cron table. It opens the cron table in the default text editor

  • Minute (0-59)

  • Hour (0-23)

  • Day of the month (1-31)

  • Month (1-12 or names like Jan, Feb, etc.)

  • Day of the week (0-7 or names like Sun, Mon, etc. where 0 and 7 represent Sunday)

The schedule is specified by providing values or ranges for each of these columns. For example, to run a task every day at midnight, you might specify 0 0 *.

  1. User management in Linux involves creating, modifying, and deleting user accounts to control access to resources and maintain system security.

Creating a User: To create a new user account in Linux, you can use the adduser or useradd command. These commands typically add a new user to the system

In this blog, we delved into the essential aspects of advanced Linux shell scripting for DevOps engineers. We explored how mastering Linux commands can significantly enhance productivity by automating tasks and improving user and permission management within a system, thereby contributing to a more secure and organized environment