Advanced Linux Shell Scripting for DevOps Engineers with User management

Advanced Linux Shell Scripting for DevOps Engineers with User management

#day5 of #90DaysOfDevOps Challenge

Task:

Create a Script for creating multiple directories.

Write a bash script createDirectories.sh that when the script is executed with three given arguments (one is the directory name and the 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.

Create a Script to back up all your work done till now

Tar Command:

The tar command is short for tape archive in Linux. This command is used for creating Archive and extracting the archive files. In Linux, it is one of the essential commands which facilitate archiving functionality. We can use this command for creating uncompressed and compressed archive files and modifying and maintaining them as well.

Syntax: tar cvf file.tar *.txt

Options in tar command:

  1. -c: This option is used for creating the archive.

  2. -f: This option is used for creating an archive along with the provided name of the file.

  3. -x: This option is used for extracting archives.

  4. -u: It can be used for adding an archive to the existing archive file.

  5. -t: It is used for displaying or listing files inside the archived file.

  6. -A: This option is used for concatenating the archive files.

  7. -v: It can be used to show verbose information.

  8. -j: It is used for filtering archive tar files with the help of tbzip.

  9. -z: It is a zip file and informs the tar command that makes a tar file with the help of gzip.

  10. -r: This option is used for updating and adding a directory or file in an existing .tar file.

  11. -W: This option is used for verifying the archive file.

  1. Read About Cron and Crontab, to automate the backup Script

Cron-

The cron can be defined as a software utility that is provided by a Linux-like OS that operates the scheduled operation on a predetermined period. It's a daemon process and executes as a background process. It performs the described tasks at a predefined period when a condition or event is encountered without user intervention.

Crontab fields:

User Management:

A user is an entity, in a Linux operating system, that can manipulate files and perform several other operations. Each user is assigned an ID that is unique for each user in the operating system.

  1. /etc/passwd

    The local user database in Linux is /etc/passwd directory.

    Create 2 users and just display their Usernames

    1. to add user

      • useradd <username>
    2. display Usernames

      • cat /etc/passwd |egrep -i '<username>|<username>'

Thanks for reading!!!!!!!