DAY-5 Advanced Linux Shell Scripting for DevOps Engineers with User management
Table of contents
- <mark>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.</mark>
- <mark>Create a Script to backup all your work done till now.</mark>
- <mark>Create 2 users and just display their Usernames</mark>
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.
syntax:
#!/bin/bash
dir_name=$1
start=$2
end=$3
for ((i=$start; i<=$end; i++ ))
do
mkdir "$dir_name$i"
done
echo "your directories generated successfully"
error will come, due to not having permission. so, give it permission
chmod 700
createDirectories.sh
then, run ./createDirectories.sh day 01 90
I have taken an example from 01 to 90. you can take as your wish.
Example 2: When the script is executed as
./
createDirectories.sh
Movie 20 50
then it creates 50 directories as Movie20 Movie21 Movie23 ...Movie50
Create a Script to backup all your work done till now.
syntax: #!/bin/bash
backup_dir="/home/soumya/devops/dirs"
backup_date="$(date +%Y-%m-%d_%H%M%S)"
backup_name="backup_${backup_date}"
backup_path="${backup_dir}/${backup_name}"
tar czf "$backup_path.tar.gz" .
echo "Backup crated successfully at: $backup_path.tar.gz"
bash backup.sh
Create 2 users and just display their Usernames
syntax:
sudo useradd test
sudo passwd test
sudo useradd test2
sudo passwd test2
sudo cat /etc/passwd