Advanced Linux Shell Scripting for DevOps Engineers with User management

Advanced Linux Shell Scripting for DevOps Engineers with User management

Introduction🌟

Welcome to our exciting journey into the world of advanced shell scripting! 🎉 Whether you're a tech enthusiast or a non-IT person curious about automation, this blog is your one-stop guide to mastering the magic of Bash scripting. Let's dive in and make things happen with just a few lines of code! 🚀

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

User input :

Output after taking the input from variables :

  1. another way,

    User input :

Output after taking the input from variables :

Create a Script to back up all your work done till now.📂

Imagine your work suddenly disappears! 😱 No worries, creating a backup of your precious work! 💾

User input :

Output after taking the input :

What is Cron & Crontab?⏰

Ever wanted to automate tasks like magic? Well, meet Cron, your time-traveling assistant! With Cron and Crontab, you can schedule tasks to happen at specific times. It's like setting an alarm for your computer! ⏱️

Cron is a time-based job scheduler in Unix-like operating systems. It allows you to automate tasks at specified intervals. Crontab is the configuration file used to manage cron jobs. Cron expressions consist of five fields, representing minutes, hours, days of the month, months, and days of the week. Each job is recorded in /etc/crontab on a single line that contains values in a specific order:

[Minute] [Hour] [Day_of_the_Month] [Month_of_the_Year] [Day_of_the_Week] [command]

Values

Minute 0 – 59
Hour 0 – 23
Day of month 1 – 31
Month of year 1 – 12
Day of week 0 – 7 ( 0 and 7 are used for Sunday)

Some more examples:

A) To schedule a cron to execute at 2 am daily
0 2 * * * /bin/sh backup.sh

B) To schedule a cron to execute twice a day at 5 AM and 5 PM daily
0 5,17 * * * /scripts/script.sh

C) To schedule a cron to execute every Sunday at 5 PM
0 17 * * sun /scripts/script.sh

User Management In Linux 🤖

Managing users on a Linux system is a fundamental administrative task. User management in Linux is the process of creating, modifying, and deleting user accounts on a Linux system. Let's explore how to create users and display their names using shell scripting.

Create 2 users and display their names👥

create users :

display their names:

Conclusion 🌅

Shell scripting opens up a world of possibilities for automating tasks on a command-line interface. From creating dynamic directories to managing users and scheduling tasks with Cron, you now have a solid foundation for advanced shell scripting. Remember, practice makes perfect! Experiment with these concepts and explore more advanced scripting techniques to further enhance your automation skills. Happy scripting!🚀💡