DevOps (Day-5)

DevOps (Day-5)

Advance Linux Scripting

  1. 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.

    Scenario 1: When the script is executed as

    ./createDirectories.sh day 1 90

    then it creates 90 directories as day1 day2 day3 .... day90

Scenario 2: When the script is executed as

./createDirectories.sh Movie 20 50 then it creates 50 directories as Movie20 Movie21 Movie23 ...Movie50

  1. Create a Script to backup all your work done till now.

    Read About Cron and Crontab, to automate the backup Script

    Linux Command Line: Cron Jobs - Snipcademy

    Crontab – Quick Reference

    Crontab is used to automate the scripts that will run in a set time interval. The format of setting the rules is as shown in the above picture.

    How to Add/Edit Crontab

    Crontab files are typically stored in the /etc/cron.d/ directory on Linux systems. The crontab command can be used to edit the crontab file.

    crontab -e

    By default, it will edit the crontab entries of the currently logged-in user. To edit other user crontab use the command below:

    crontab -u username -e

    How to List Crontab

    To view the crontab entries of current users use the following command.

    crontab -l

    Use -u followed by the username to view the crontab entries of the specified user.

    crontab -u username -l

    Automating the backup script through crontab.

    The script will run 1st of every month.

    1. User management in Linux

      root - It is the superuser that can perform all the actions in a server. This privilege is given at the time of server spin-up.

      With useradd commands, you can add a user.

      Syntax:

      useradd -c "comment" username

      To delete a user account userdel command is used.

      Syntax:

      userdel -r <userName>

      The command usermod is used to modify the properties of an existing user.

      Syntax:

      usermod -c <'newName'> <oldName>

      /etc/passwd - This file contains the detailed information of all the users created in a server.

    2. Create 2 users and just display their Usernames.