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.

  1. Write a shell script function to find and kill all the zombie processes.

  2. Find the first 10 biggest files in the file system and write the output to a file.

  3. Shell script to gracefully unmount a disk.

  4. shell script to send email

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

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

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

  8. Write a shell script to the list of users logged in by date and write it to an output file.

  9. Shell script to Copy files recursively to remote hosts

  10. Shell script that displays the number of failed login attempts by IP address and location.

  11. Shell script parses a log file and forwards a specific value with a timestamp to an output file.

  12. Write a shell script to automate the process of rotating log files and compressing old files to save disk space.

  13. Write a shell script to check the status of a list of URLs and send an email notification if any of them are down.

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

  1. variable definitions

  2. Use cut, awk, and grep

  3. Handling Input/output /error redirections.

  4. Conditions/If else statements

  5. Case statement scripts

  6. Loops (For/Do-While)

  7. Exist status

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

  1. Powershell

  2. Python

  3. Pearl

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

  1. Can you explain how shell scripting fits into a larger DevOps workflow?

  2. What is the need for shell scripts when there are automation tools to do the work?

  3. In what scenarios would you opt for shell script rather than programming languages like Python or Golang?

  4. How would you approach writing a shell script to automate a particular task?

  5. How to do static analysis for Shell script?

  6. How do you ensure that shell scripts are error-free in your CI/CD pipeline?

  7. How can you handle errors and exceptions in shell scripts?

  8. Shell script to reverse a string

  9. Parse a log in the desired format and find all occurrences of a word

  10. Shell script to send the first ten lines of a file to another file.

  11. Merge(concatenate) two files and write the output to the third file.

  12. Find all duplicate strings in a file and replace them with another string

  13. Find all the IP addresses from a log file and write it to another file.

  14. How would you debug a shell script that isn’t working correctly?

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