QUICK TIP - Useful Bash Scripts Linux – 9 Interview questions (updating)

0 65,677
complete_linux_training_course_to_get_your_dream_it_job_2019.jpg | A&H Business Technology
Related posts

Useful Bash Scripts – Linux – interview questions you should know. Why? These Bash Scripts are not only useful in practical situations but also you often face to the Bash Scripts questions from the interview. We are surveying and selecting the questions and giving you answers for referencing. We still keep update more on this post.

Okay. We are all ready. Let’s go!

1. Using Bash Scripts: How to read a text file with IPs list? Then check online IPs and add these IPs to a new file?

Answer: In order, giving a full answer for this Bash Scripts question, you should answer following this step-by-step.

Check IPs list file using Linux command: Cat

The bash scripts below shows you how to check the file is available, corruption or not… This step prepares for next step and also let the interviewers you are professional troubleshooting. We need to check the input first before going to write a Bash Script.

The example below shows us some example IPs. In the practical context, there are many IPs in text file. It may contain from 1k up to 1000k IPs.

Explanation: Cat is a Linux command which lists out and displays information in a text file in this situation.

Note: You can get more points from interviewers if you can show this step, although it is simple and easy. They will know that you are a professional IT and also a good preparation and careful guy. In many large organisation and big system, you should be careful and well-preparation.

Write a Bash Script to answer the question

Using Cat to create a script file in Linux. Firstly, we need a variable to store a string. This string will be the ips list text file that will store all alive ips after checking step. In addition, this step also need a WHILE loop to read and ping all ips in iplist.txt.

Explanation: Cat is a Linux command which creates new bash script file in this situation.

Now, we need to understand how this script works:  ping -c 1 $ips

If an IP is alive, the result of the bash script will be the image below:

Bash Script - ping command

If an IP is died, the result of this bash script will be the image below:

Bash Scripts - Ping Ip dieif [ $? -eq 0 ]; then, this line will check the value after ping command is executed.

echo $ips >> $up_ipfile, this line will write the IP to text file if it is alive.

Run the script after making it executable


Create a file with IP’s which are alive


2. Using Bash Scripts: How to read a list of users from a text file then create a folder and add right for all users as read only?  Text file format: <username>:<fullname>:<usergroups>

If you face to the question like this, you should panic. In order to answer the question, you should keep calm and think. You should do the following steps below:

TinyURL for this post: https://tinyurl.com/y5m7q53x

Sorry, The Comment Form Is Temporarily Closed At This Time
You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More