Day 5 Task: Advanced Linux Shell Scripting for DevOps Engineers with User management.

Example 1: When the script is executed as
./createDirectories.sh day 1 90
then it creates 90 directories as day1 day2 day3 .... day90
./createDirectories.sh Movie 20 50 then it creates 50 directories as Movie20 Movie21 Movie23 ...Movie50
#!/bin/bash
Folder_name=$1
start=$2
end=$3
for ((i=start;i<=end;i++))
do
mkdir "$Folder_name$i"
done

Create a Script to Backup all your work done till now.
#!/bin/bash
source=/home/ubuntu/my_scripts
target=/home/ubuntu/devops/backup
tar -czvf $target/$1tar.gz $source
echo "backup completed"


Read About Cron and Crontab, to automate the backup Script
Cron is a utility in Unix-like operating systems that allows users to schedule and automate tasks to run at specified intervals. Crontab is a file that contains the commands or scripts to be executed by cron.
To automate a backup script using cron and crontab, you can follow these steps:
Create a backup script: Write a shell script that performs the backup of your data.
Set the file permissions: Ensure the script is executable by running the command
chmod +x backup_script.sh.Open the crontab file: Run the command
crontab -eto open the crontab file.Schedule the backup script: In the crontab file, specify the time and frequency at which you want the backup script to run. For example, to run the script daily at 2 am, add the following line to the crontab file:
0 2 * * * /path/to/backup_script.sh
- Save the crontab file: Save and close the crontab file.
Now, the backup script will run automatically at the scheduled time and frequency specified in the crontab file. You can check the log files to ensure that the backup script is running as expected.
User Management
In Linux, user management involves creating, modifying, and deleting user accounts. Here are some of the basic commands that you can use to manage users in Linux:
- Creating a user: You can create a user account using the
useraddcommand. For example, to create a user named "john", run the command:
sudo useradd john
- Setting a password: To set a password for the new user, use the
passwdcommand. For example:
sudo passwd john
- Modifying a user: You can modify a user's account details using the
usermodcommand. For example, to add the user "john" to the "sudo" group, run the command:
sudo usermod -aG sudo john
- Deleting a user: To delete a user account, use the
userdelcommand. For example, to delete the user "john", run the command:
sudo userdel john
- Listing users: To list all users on the system, use the
catcommand to read the/etc/passwdfile. For example:
cat /etc/passwd
These are some of the basic commands for managing user accounts in Linux. It's important to note that user management can vary depending on the Linux distribution you're using.
Create 2 users and just display their Usernames
sudo useradd user1 (create user1)
sudo useradd user2 (create user2)
cat /etc/passwd | grep "username" (to find usernames)
cut -d: -f1 /etc/passwd | grep "^user"
(to display:This command uses the cut command to extract the first field (i.e., the username) from the /etc/passwd file, and the grep command to filter out any usernames that don't start with the prefix "user")





