Day 5: Advanced Linux Shell Scripting
Day 5 Task: Advanced Linux Shell Scripting for DevOps Engineers with User management
Day5 Task
🔹Create a Script to back up all your work done till now.
🔹Read About Cron and Crontab, to automate the backup Script.
🔹Read about User Management
🔹Create 2 users and just display their Usernames.
🔹Create a Script to back up all your work done till now.
🔸Script for back up all the work which we have done till now.
#!/bin/bash
backup_direcrtory="/path/to/backup"
source_direcrtory="/path/to/source"
current_timestamp=$(date "+%Y-%m-%d-%H-%M-%S")
tar -czvf "$backup_directory --$src_dir
echo "All Backup"
🔹About Cron and Crontab, to automate the backup Script.
Cron and crontab:
🔸Crontab: crontab is the configuration file used to define cron jobs .it holds the schedule.
Cron is the system's main scheduler for running jobs or tasks unattended. A command called crontab allows the user to submit, edit or delete entries to cron.
🔹To view the crontab file, use the following command:
$ crontab –l
🔹To view the crontab file of a particular user, use the following command:
$ sudo crontab –u user -l
🔹To edit the crontab file of the current user:
$ crontab –e
🔹To edit the crontab file of a particular user:
$ sudo crontab -u user
🔹About User Management
🔸user management revolves around creating, modifying, and deleting user accounts, managing permissions, and controlling access to system resources.
Some User Management Commands
🔹This is the command to add a user. useradd command adds a new user to the directory.
sudo useradd <username>
🔹This passwd command to assign a password to a user:
sudo passwd <username>
🔹Using the id command,you can get the ID of any username:
id <username>
🔹Create 2 users and just display their Usernames.
🔸Here I am creating users as user1 and user2 and displaying their Usernames on the output.
sudo useradd user1
sudo useradd user2
echo "User A: $(id -un user1)"
echo "User B: $(id -un user2)"
Thanks for reading to the end; I hope you gained some knowledge.❤️🙌