Shell Scripting For Devops :
Shell : Shell is a utility to communicate with kernel .
I am using two types of shell 1. sh 2.bash
Script: A Shells are tools that let us interact with the kernel. I use two types of shells: 1. sh and 2. bash
sh: This is a type of shell used for writing scripts.
bash (Bourne Again Shell): This is another type of shell, more popular and advanced than sh.
Script: A combination of shell command :
A shell script ends with the .sh extension and starts with a shebang [#!/bin/bash].
Comments: There are two types of comments used in Shell Scripting:
Single Line Comments
Multi-Line Comments
Single line comments start with #
, and multi-line comments start with <<name
and end with name
.
Variables and Constants:
a=2
a is a variable, and 2 is a constant. Variables can change, but constants have a fixed value can't change .
Variables: Used to store and manipulate data in scripts. They can be changed and accessed using the $
symbol.
Taking Input From User :
There are two ways
read variable_name
#!/bin/bash
echo "Please enter your name:" read user_name
echo "Hello, $user_name!"
read -p "Enter your favorite color: " color echo "Your favorite color is $color."
Installing nginx with ShellScript :
Installing Packages With Arguments:
Conditional [if-elif]:
Backups :
I learned about some following backups :
zip -r <backup-file-name.zip <path/to/script-folder>
zip
: The command used to create a zip archive.r
: This option stands for "recursive," meaning it will include all files and directories within the specified folder.Taking backup with passing sources as argument and adding the timestamp.
i write script for it .
Auto backup for 2min/10min/1hr etc . Using Tool name is cron.
crontab -e
learn about this tool deeply on crontab.guru
* command_to_execute
Where the five asterisks represent:
Minute (0-59)
Hour (0-23)
Day of Month (1-31)
Month (1-12)
Day of Week (0-6, where 0 is Sunday
Function in ShellScriipting :
stx:
function_name() { # commands }
I write ShellScripts for backups, package installation, conditionals, variables, arguments, and nginx installation. You can find all of these on my GitHub account..
Here is the link of github profile :https://github.com/Dinesh-Khade
Here is the Link of Shell Script for Devops repo :https://github.com/Dinesh-Khade/Shell_Scripting-for_Devops.git
Subscribe to my newsletter
Read articles from Dinesh khade directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Dinesh khade
Dinesh khade
I am learning about Devops and Devops Tools .