Day 5: DevOps ❤️

Table of contents

No heading

No headings in the article.

  1. Write a bash script 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.

     #!/bin/bash
    
     directory=$1
     start_day=$2
     end_day=$3
    
     for n in $(seq $start_day $end_day);
     do
       mkdir $directory$n
     done
    
  2. Create a Script to back up all your work done till now.

     #!/bin/bash
     backup_dir="/home/ubuntu"
     backup_file="mybackup_$(date +"%Y%m%d_%H%M%S").tar.gz"
     tar -czf "$backup_dir/$backup_file" /home/ubuntu/
    
     if [ -f "$backup_dir/$backup_file" ]; then
       echo "Backup created successfully!"
     else
       echo "Error: Backup creation failed!"
       exit 1
     fi
    
  3. Read About Cron and Crontab, to automate the above backup Script

     crontab -e
     * * * * * bash /home/ubuntu/backupscript.sh
    

    The above command will create a backup script every 1 minute.

  4. Create 2 users and just display their Usernames

     sudo useradd umang_pincha -m
    

Bye GIFs - Get the best gif on GIFER