Day 4 Task: Basic Linux Shell Scripting for DevOps Engineers
What is Shell?
A shell is a special user program that provides an interface for users to interact with operating system services. It accepts human-readable commands from users and converts them into instructions that the kernel can understand. The shell is a command language interpreter that executes commands read from input devices such as keyboards or from files. It starts when the user logs in or opens a terminal.
What is Linux Shell Scripting?
Linux shell scripting involves writing programs (scripts) that can be run by a Linux shell, such as bash (Bourne Again Shell). These scripts automate tasks, perform system administration tasks, and facilitate the interaction between users and the operating system.
Explain in your own words and with examples what Shell Scripting means for DevOps.
Shell scripting is a crucial skill for DevOps professionals. It involves writing scripts in a shell (command-line interpreter) to automate tasks that would otherwise need to be performed manually. Shell scripts can handle a variety of tasks such as system administration, software deployment, task scheduling, and more.
Examples in DevOps:
Automating Deployment:
Writing a script to deploy an application to multiple servers, ensuring each server is configured correctly.
Example: A script to pull the latest code from a Git repository and restart the application.
Monitoring Systems:
Creating scripts that check the health of services and notify the team if something goes wrong.
Example: A script that pings servers and sends an email if any server is down.
Backup and Restore:
Automating the backup of databases and critical files.
Example: A script that backs up a database every night and stores the backup in a secure location.
What is #!/bin/bash
? Can we write #!/bin/sh
as well?
The line #!/bin/bash
at the beginning of a shell script is called a shebang. It tells the system which interpreter to use to execute the script. In this case, it specifies the Bash shell.
#!/bin/bash
specifies that the script should be run using the Bash shell.Yes, you can write
#!/bin/sh
as well, which will use thesh
shell (Bourne shell). Thesh
shell is a more basic shell compared to Bash and might not support some of the advanced features available in Bash.
Write a Shell Script that prints I will complete #90DaysOfDevOps challenge
.
Write a Shell Script that takes user input, input from arguments, and prints the variables.
Provide an example of an If-Else statement in Shell Scripting by comparing two numbers.