Basic Linux Shell Scripting for DevOps Engineers and Real-world Shell Scripting Use Cases.
Real-world Shell Scripting Use Cases
It is always better to learn with some real-time scenarios in terms of DevOps engineer interviews. So I have come up with some real-world scenarios you can try out. I will keep updating this list.
Write a shell script function to find and kill all the zombie processes.
Find the first 10 biggest files in the file system and write the output to a file.
Shell script to gracefully unmount a disk.
shell script to send email
Shell script to monitor CPU, Memory, and Disk usage and send the output to a file in table format and send an alert if either of them exceeds a certain threshold.
Shell script to find the files created and their sizes. It should accept the number of days as input. Or a from and to date format as inputs.
Write a shell script to automate the process of creating new user accounts on a Linux server and setting up their permissions and SSH access.
Write a shell script to the list of users logged in by date and write it to an output file.
Shell script to Copy files recursively to remote hosts
Shell script that displays the number of failed login attempts by IP address and location.
Shell script parses a log file and forwards a specific value with a timestamp to an output file.
Write a shell script to automate the process of rotating log files and compressing old files to save disk space.
Write a shell script to check the status of a list of URLs and send an email notification if any of them are down.
Write a shell script to automate the process of updating a list of servers with the latest security patches.
Ensure you include the following concepts in the shell scripts you are writing.
variable definitions
Use cut, awk, and grep
Handling Input/output /error redirections.
Conditions/If else statements
Case statement scripts
Loops (For/Do-While)
Exist status
Command line arguments
Shell Scripting Languages
First of all, there are no specific shell scripting languages. When it comes to Shell scripting, it refers to sh, bash, csh, tcsh
. Here we are primarily talking about bash shell scripting. Bash is an interpreted scripting language for Unix-based systems.
But scripting languages, in general, means multiple languages. The following are the common scripting languages.
Powershell
Python
Pearl
Groovy
Shell Scripting DevOps Interview Questions
Shell scripting DevOps interview questions differ from company to company.
For example, a Service based company would be just interested in your basic Linux and shell scripting knowledge. However, a product-based company might expect a good level of knowledge of Linux command line and shell scripting.
Nowadays, most companies would provide platforms like Hackerank to test your scripting skills. So it is necessary to practice shell scripting to solve problems.
Following are some of the DevOps interview shell script questions.
Can you explain how shell scripting fits into a larger DevOps workflow?
What is the need for shell scripts when there are automation tools to do the work?
In what scenarios would you opt for shell script rather than programming languages like Python or Golang?
How would you approach writing a shell script to automate a particular task?
How to do static analysis for Shell script?
How do you ensure that shell scripts are error-free in your CI/CD pipeline?
How can you handle errors and exceptions in shell scripts?
Shell script to reverse a string
Parse a log in the desired format and find all occurrences of a word
Shell script to send the first ten lines of a file to another file.
Merge(concatenate) two files and write the output to the third file.
Find all duplicate strings in a file and replace them with another string
Find all the IP addresses from a log file and write it to another file.
How would you debug a shell script that isn’t working correctly?
What is the difference between a “for” loop and a “while” loop in shell scripting?
I will be updating the list with more generic interview questions soon.