Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 4 MCQs Advanced Bash Scripting & Automation

CSC104 — It Fundamentals 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 Multi-function scripting Easy

    What is the main purpose of using functions in a Bash script?

  2. Question 2 of 60 Multi-function scripting Easy

    Which syntax correctly calls a Bash function named backup_files?

  3. Question 3 of 60 Interactive menu with colors Easy

    Which Bash command is commonly used to read a user's menu choice?

  4. Question 4 of 60 Interactive menu with colors Easy

    What is commonly used to display colored text in a Bash menu?

  5. Question 5 of 60 Remote script execution Easy

    Which command is commonly used to execute commands securely on a remote Linux server?

  6. Question 6 of 60 Remote script execution Easy

    In the command ssh admin@example.com, what does admin represent?

  7. Question 7 of 60 Working with JSON via jq Easy

    What is jq primarily used for in shell scripts?

  8. Question 8 of 60 Working with JSON via jq Easy

    Which command extracts the name field from data.json using jq?

  9. Question 9 of 60 Cloudflare API integration Easy

    What does an API token provide when a script accesses the Cloudflare API?

  10. Question 10 of 60 Cloudflare API integration Easy

    Which command-line tool is commonly used to send HTTP requests to the Cloudflare API?

  11. Question 11 of 60 Access log summarizer Easy

    What information is commonly recorded in a web server access log?

  12. Question 12 of 60 Access log summarizer Easy

    Which command is useful for counting lines in an access log?

  13. Question 13 of 60 Sending emails with SSMTP Easy

    What is SSMTP used for in a Bash automation script?

  14. Question 14 of 60 Sending emails with SSMTP Easy

    Which piece of information identifies the server used to send email through SSMTP?

  15. Question 15 of 60 Password generator Easy

    Which property is most important for passwords created by an automated generator?

  16. Question 16 of 60 Password generator Easy

    Which Linux source can provide random bytes for a Bash password generator?

  17. Question 17 of 60 Pipes versus redirection Easy

    What does the pipe operator | do in Bash?

  18. Question 18 of 60 Pipes versus redirection Easy

    What does > do in the command date > today.txt?

  19. Question 19 of 60 Automated WordPress setup on LAMP stack Easy

    In the term LAMP, what does the letter A represent?

  20. Question 20 of 60 Automated WordPress setup on LAMP stack Easy

    Why does an automated WordPress setup script create a database?

  21. Question 21 of 60 Multi-function scripting Medium

    A Bash script defines backup_files() and show_usage(). Which approach correctly calls show_usage when the user supplies no command-line arguments?

  22. Question 22 of 60 Multi-function scripting Medium

    A function must calculate a directory size and make that value available to the calling code. Which implementation is most suitable for command substitution?

  23. Question 23 of 60 Interactive menu with colors Medium

    An interactive Bash menu prints colored choices, but text entered afterward remains green. Which change should be made after printing each colored line?

  24. Question 24 of 60 Interactive menu with colors Medium

    Which Bash structure most directly handles menu choices such as 1, 2, and q while also providing a response for invalid input?

  25. Question 25 of 60 Remote script execution Medium

    A local script named audit.sh must run on server1 without first being copied to a remote file. Which command sends it through SSH correctly?

  26. Question 26 of 60 Remote script execution Medium

    A remote command contains $HOSTNAME, which must be expanded by the remote shell rather than the local shell. Which command preserves it until remote execution?

  27. Question 27 of 60 Working with JSON via jq Medium

    Given {"users":[{"name":"Ana","active":true},{"name":"Ben","active":false}]}, which jq filter prints only the name of each active user?

  28. Question 28 of 60 Working with JSON via jq Medium

    A script stores an API response in response and needs the raw string value of its .id field without JSON quotation marks. Which command should it use?

  29. Question 29 of 60 Cloudflare API integration Medium

    A script updates a Cloudflare DNS record through the API. Which combination should normally appear in the authenticated HTTP request?

  30. Question 30 of 60 Cloudflare API integration Medium

    Before updating a Cloudflare DNS record, a script queries records by name. Why should it extract the record ID from the response?

  31. Question 31 of 60 Access log summarizer Medium

    In a standard combined Apache access log, the client IP address is the first whitespace-separated field. Which pipeline lists the ten most frequent client IPs?

  32. Question 32 of 60 Access log summarizer Medium

    An Apache log uses combined log format, where the quoted request is fields 6 through 8 and the status code is field 9. Which command counts only HTTP 404 responses?

  33. Question 33 of 60 Sending emails with SSMTP Medium

    A Bash script creates a complete email containing To: and Subject: headers in message.txt. Which command submits it through SSMTP?

  34. Question 34 of 60 Sending emails with SSMTP Medium

    A scheduled backup script should send an email only when backup.sh fails. Which condition correctly triggers the SSMTP command?

  35. Question 35 of 60 Password generator Medium

    Which command generates a 20-character password from letters, digits, and selected symbols using random bytes from the operating system?

  36. Question 36 of 60 Password generator Medium

    A password script uses random=$RANDOM$RANDOM and then truncates the result. What is the main security weakness of this approach?

  37. Question 37 of 60 Pipes versus redirection Medium

    Which statement correctly describes producer | consumer > result.txt?

  38. Question 38 of 60 Pipes versus redirection Medium

    A script must save both standard output and standard error from deploy.sh into deploy.log. Which Bash command performs this correctly?

  39. Question 39 of 60 Automated WordPress setup on LAMP stack Medium

    During an automated WordPress installation, which database setup follows the principle of least privilege?

  40. Question 40 of 60 Automated WordPress setup on LAMP stack Medium

    An installation script may be run more than once. Which design best makes the WordPress database creation step idempotent?

  41. Question 41 of 60 Multi-function scripting Hard

    A Bash function must compute a value for command substitution while also reporting diagnostics. Which implementation preserves the computed output in result=$(calculate) without mixing diagnostics into it?

  42. Question 42 of 60 Multi-function scripting Hard

    A script enables set -e and defines an ERR trap, but failures inside called functions do not consistently trigger the trap. Which additional setting makes the ERR trap inherited by shell functions, command substitutions, and subshells?

  43. Question 43 of 60 Interactive menu with colors Hard

    An interactive colored menu is also executed by cron, where its output is redirected to a log. Which condition should control whether ANSI color sequences are emitted?

  44. Question 44 of 60 Interactive menu with colors Hard

    A menu temporarily disables terminal echo while reading a secret. Pressing Ctrl+C sometimes leaves the terminal unusable and colored output unreset. Which design most reliably restores both states?

  45. Question 45 of 60 Remote script execution Hard

    A local script must pass an arbitrary argument, including spaces and shell metacharacters, to bash -s on a remote Bash host. Which pattern safely constructs the remote command?

  46. Question 46 of 60 Remote script execution Hard

    The command ssh host 'sudo bash -s' < deploy.sh hangs because remote sudo requests a password while standard input already carries the script. For unattended automation, which change is most appropriate?

  47. Question 47 of 60 Working with JSON via jq Hard

    Given an array of request objects, which jq filter returns one object mapping each HTTP status to its occurrence count, such as {"200": 8, "404": 2}?

  48. Question 48 of 60 Working with JSON via jq Hard

    A shell variable name may contain quotes, newlines, or backslashes. Which command safely creates the JSON object {"name": <value>} without manual escaping?

  49. Question 49 of 60 Cloudflare API integration Hard

    A script calls the Cloudflare API with curl, and an HTTP 400 response still leaves curl with exit status 0. Which invocation best lets the script capture the JSON error body while also treating HTTP errors as command failures?

  50. Question 50 of 60 Cloudflare API integration Hard

    A zone has more DNS records than the API's per_page limit. Which termination condition correctly drives a pagination loop using Cloudflare's result_info metadata?

  51. Question 51 of 60 Access log summarizer Hard

    In a standard combined access log, the request and user-agent fields contain spaces inside quotes. Which strategy most reliably counts response status codes without assuming that every whitespace-separated field has a fixed position?

  52. Question 52 of 60 Access log summarizer Hard

    A summarizer must process access.log plus rotated files ending in .gz as one stream. Which Bash pattern handles filenames safely and decompresses only the compressed files?

  53. Question 53 of 60 Sending emails with SSMTP Hard

    Which message structure is required when piping a complete email to ssmtp recipient@example.com?

  54. Question 54 of 60 Sending emails with SSMTP Hard

    A backup script uses generate_report | ssmtp admin@example.com, but with default pipeline semantics it can report success when generate_report fails and ssmtp exits successfully. Which setting makes the pipeline fail when either stage fails?

  55. Question 55 of 60 Password generator Hard

    A password generator maps each random byte to an alphabet of size using byte % 62. Which method removes modulo bias?

  56. Question 56 of 60 Password generator Hard

    A generator runs tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 24 under set -o pipefail. It sometimes reports failure despite producing 24 characters. What is the most likely cause?

  57. Question 57 of 60 Pipes versus redirection Hard

    Why does count=0; printf '%s\n' a b | while read -r x; do ((count++)); done; echo "$count" commonly print 0 in Bash, and which rewrite preserves the updates?

  58. Question 58 of 60 Pipes versus redirection Hard

    Which command sends both standard output and standard error to combined.log, replacing the file, and why is redirection order significant?

  59. Question 59 of 60 Automated WordPress setup on LAMP stack Hard

    An automated WordPress installer may be rerun after a partial failure. Which database provisioning approach is most idempotent?

  60. Question 60 of 60 Automated WordPress setup on LAMP stack Hard

    A root-run setup script downloads WordPress and executes WP-CLI. Which practice best avoids later ownership and permission failures when WordPress performs updates through the web server account?

That's unit 4

Answer a few questions and your score shows up here.