Are you a Linux sysadmin? Try our new Bash challenge and win $100 gift card!

To excel as a Linux sysadmin, you need to possess a range of skills and knowledge. Firstly, a solid understanding of the Linux operating system is essential. You should be familiar with the command line interface, file systems, process management, and networking concepts. Proficiency in scripting languages like Bash or Python is also highly advantageous for automating tasks and writing custom scripts.

Furthermore, strong problem-solving and troubleshooting abilities are crucial for resolving system issues effectively. Attention to detail, organizational skills, and the ability to work under pressure are also important qualities for a Linux sysadmin.

Try to solve the questions below for the chance to win $100 gift card at desired online store. You have until June 19th to send us your answers. 

Email your answers to quiz@embedl.com 

 

Questions

These questions assume the shell is GNU Bash.

1. Failing pipes

A Linux command will typically return with exit code 0 if it’s been successful, and non-zero if there was an error (often exit code 1, unless the process is trying to tell us something specific). When using a pipe, more than one command is involved. Consider:

 grep == requirements.txt | sort | uniq

Will the command as a whole be successful if (a) grep fails, but sort and uniq run successfully, (b) sort fails, but grep and uniq run successfully, (c) uniq fails, but grep and sort run successfully, (d) all sub-commands are successful, (e) all sub-commands fail.

How can I test this? Is there any shell option to tweak this behavior?

 

2. Sorting standard error output

Assume there’s a command named mytestcommand that writes several lines to both standard output and standard error output. If we want to sort the lines that go to the standard output, we can do it with 

 mytestcommand | sort

Now, suppose we want to sort the standard error output instead. Can you do it (a) so that both stdout and stderr are sorted together? Can you do it (b) so that only stderr is sorted, but the stdout is left unaffected? 

 

3. Map that file

The mapfile command is built into Bash. It’s description is

Read lines from the standard input into the indexed array variable ARRAY, or from file descriptor FD if the -u option is supplied. The variable MAPFILE is the default ARRAY.

What is the difference between this pipe:

grep == requirements.txt | mapfile; echo "${#MAPFILE[*]}"

… and the following redirection?

mapfile < <(grep == requirements.txt); echo "${#MAPFILE[*]}"

Will they do the same thing? What is the advantage of using the < <() syntax? What is the advantage of using the pipe syntax? If I really want to use the pipe syntax, can we work around any potential issue with the first approach? (In a realistic scenario,  echo

Screenshot 2023-07-13 at 10.42.58may be replaced with some for loop over the entries in the array.)

 

4. exec redirections

What on Earth is happening here? Why would anyone do it like that? Will it even work?

local test_targets_file_write local test_targets_file_read declare -r test_targets_file=$(mktemp) exec {test_targets_file_write}>"$test_targets_file" exec {test_targets_file_read}<"$test_targets_file" rm "$test_targets_file" find tests -name 'test*.py' | \ testfile2targetname | \ sort >&"$test_targets_file_write" declare -a test_targets mapfile -t test_targets <&"$test_targets_file_read" readonly test_targets

 

5. The greater pipe

What does this do?

 grep == requirements.txt >| sort

Is this a file redirection or a command pipe? What’s the difference between > and | and >|? When would you use one or the other?

 

6. :(){ :|:;};:

What does this command do? Think it through before you try it.

 :(){ :|:;};:

 

7. If two people are equally good at bash scripting, this question will determine who gets the prize:

Embedl has most code in a monorepo. In this repository, what percentage of source lines of code (SLOC) are (A) Python, (B) Shell script and (C) other languages, as measured by David A. Wheeler's 'SLOCCount'?

Answer in percent with two decimal places. 

 

Email your answers to quiz@embedl.com

You may also like

Answers to the Linux Sysadmin Bash Challenge
Answers to the Linux Sysadmin Bash Challenge
3 August, 2023

Congratulations to Henning Phan and Christian Jenei, the winners of our thrilling Bash challenge! Their exceptional prob...

SMALLER FOOTPRINT IN DEVICE
SMALLER FOOTPRINT IN DEVICE
17 April, 2023

One of the many challenging tasks when deploying deep learning models on resource-constrained devices such as embedded s...

Introduction to Deep Learning in the Automotive Industry
Introduction to Deep Learning in the Automotive Industry
9 May, 2023

Deep Learning in the Automotive Industry As the world becomes increasingly digital, the automotive industry is quickly c...