My Journey into DevOps:Scripting, Automation, and User Management
Introduction
Welcome back to my DevOps journey! Day 5 was all about scripting, automation, and user management. I learned how to create directories, automate backups, and manage users on a Linux system. Let's dive into the details of what I accomplished on this exciting day.
Creating Directories with a Bash Script
One of the first tasks of the day was to create a Bash script that could generate a specified number of directories with dynamic names. This would save time compared to creating directories manually. Here's how I did it:
I created a script named createDirectories.sh and made it executable using chmod +x createDirectories.sh. With this script, I could create directories with names like day 1, day 2, and so on. The script took three arguments: the directory name, the start number, and the end number. This allowed me to create directories with names like day 1, day 2, day 3, and so on, up to a specified range. I could also create directories with different names if needed.
Automating Backups
In the world of DevOps, backups are crucial. I created a backup script, backup.sh, that allowed me to back up my work with a single command. This script took care of copying the contents of a source directory to a backup folder, creating a timestamped backup directory to keep things organized.
With this script, I could easily create backups of my work by specifying the source directory and the backup destination. Automating backups not only saved time but also ensured the safety of my work in case of unexpected events.
Here is the script:-
Make sure to replace /path/to/source/directory and /path/to/backup/directory with the actual source and backup directory paths. Save this script to a file, e.g., backup.sh, and make it executable as well.
Using Cron to Schedule Backups
To take automation to the next level, I explored Cron, the system's scheduler for running tasks unattended. I scheduled my backup script to run at a specific time or interval using Cron. This meant that my backups could be automatically created at regular intervals without any manual intervention. I added a line to my Crontab to specify when and how often the backup script should run. This was a fantastic way to ensure that my data was always protected.
User Management in Linux
DevOps also involves managing users on a Linux system. I learned how to create and manage users with the useradd command and how to display their usernames. User management is essential for controlling access and permissions on a system.