Advance Shell Scripting Used IN DevOps with User management.
In This Article We Will See Below Tasks on Shell Scripting
You have to do the same using Shell Script i.e using Loops with start day and end day variables using arguments.
Create a Script to back up all your work done till now.
About Cron and Crontab, to automate the backup Script.
About User Management.
Create 2 users and just display their Usernames.
So Write a bash script to create directories. sh that when the script is executed with three given arguments (one is the directory name and second is the start number of directories and the third is the end number of directories ) it creates a specified number of directories with a dynamic directory name.
In the below script, we have used 'for 'loop to satisfy the above situation
Script :
#!/bin/bash
name=$1
start_name=$2
end_name=$3
for (( i=start_name; i<=end_name; i++))
do mkdir "$name$i"
done
output :
- Create a Script to back up all your work done till now.
Script :
#!/bin/bash
src_dir=/home/ubuntu/my_scripts
tgt_dir=/home/ubuntu/Akanksha
curr_timestamp=$(date "+%Y-%m-%d-%H-%M-%S") backup_file=$tgt_dir/$curr_timestamp.tgz
echo "Taking backup on $curr_timestamp"
tar -cvzf $backup_file --absolute-names $src_dir
echo "Backup complete"
Output :
Cron and Crontab :
Cron- cron is the general name for the service that runs scheduled actions. crond is the name of the daemon that runs in the background and reads crontab files.
Crontab- Crontab is a command that is found in the Linux Operating system to Schedule tasks. Crontab stands for “cron table, ” because it uses the job scheduler cron to execute tasks.
User Management :
User management is a process to create, modify, and delete users in a Linux system. If we e create a user in a Linux system, we have to make sure that the user name is not starting with a capital letter and only with sudo permission we are allowed to perform the activity like creating, modifying or deleting users.
adduser : to add a user to the system
userdel : to delete a user from the system
usermod : to modify the user
Create 2 users and just display their Usernames
command :
output :