Unit 4 - Practice Quiz

CSC104 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 In Bash scripting, which of the following is a valid syntax for defining a function named myFunc?

A. myFunc = function() { commands; }
B. function myFunc { commands; }
C. def myFunc():
D. func myFunc() { commands }

2 When writing a multi-function script, how do you define a variable that is only accessible within the function it is declared in?

A. private var_name
B. restricted var_name
C. const var_name
D. local var_name

3 Inside a function, how do you access the first argument passed specifically to that function?

A. @{1}
B. $1
C. $ARG1
D. $0

4 Which command is used to return a numeric exit status from a function to the caller?

A. return
B. echo
C. back
D. exit

5 To enable an interactive menu, which Bash command is commonly used to accept single-character input without requiring the user to press Enter?

A. input -char
B. read -n 1
C. read -p
D. getch

6 Which ANSI escape code sequence is typically used to print text in Red?

A. \033[0;34m
B. \color{red}
C. \033[0;31m
D. \033[0;32m

7 When using ANSI escape codes for colors, what is the code \033[0m used for?

A. Make text bold
B. Reset/Normalize all attributes
C. Clear the screen
D. Set background to black

8 Which control structure is most efficient for handling multiple choices in an interactive menu script?

A. if-else chain
B. while loop
C. case statement
D. for loop

9 What is the primary command used to securely execute a script on a remote server?

A. telnet
B. ssh
C. netcat
D. ftp

10 How can you execute a local script named setup.sh on a remote server user@host without copying the file there first?

A. ssh user@host -s setup.sh
B. ssh user@host exec setup.sh
C. scp setup.sh user@host && run
D. ssh user@host < setup.sh

11 To perform remote execution without entering a password every time, which mechanism should be set up?

A. Hardcoded password in script
B. Telnet plain text
C. SSH Key-based Authentication
D. Root permission

12 Which command-line tool is specifically designed to parse, filter, and map JSON data in the terminal?

A. awk
B. jq
C. grep
D. sed

13 Given the JSON {"status": "active", "id": 50}, which jq filter extracts the value of the status?

A. jq .status
B. jq -extract status
C. jq 'status'
D. jq [status]

14 What does the jq command jq '.' do to raw JSON input?

A. Pretty-prints/Formats the JSON
B. Minifies the JSON
C. Extracts the first element
D. Deletes the JSON

15 Given a JSON array [{"id":1}, {"id":2}], how do you access the first object using jq?

A. jq .[1]
B. jq .first
C. jq .[0]
D. jq .array(0)

16 When interacting with the Cloudflare API via curl, which HTTP header is used for authentication using an API Token?

A. -u user:<TOKEN>
B. -H "X-CF-Key: <TOKEN>"
C. -H "Authorization: Bearer <TOKEN>"
D. -H "Auth: <TOKEN>"

17 Which curl flag is used to send JSON data as the payload (body) of a request?

A. -b or --body
B. -j or --json
C. -d or --data
D. -p or --payload

18 If you need to update a DNS record via Cloudflare API, which HTTP method is appropriate?

A. PUT
B. HEAD
C. DELETE
D. GET

19 In an Apache access log, which command is most suitable for extracting just the IP addresses (usually the first column)?

A. cut -c 1-5
B. sed 'delete all'
C. awk '{print $1}'
D. grep '$1'

20 When summarizing logs, what does the command sequence sort | uniq -c do?

A. Sorts lines and deletes unique lines
B. Uniquely sorts characters
C. Sorts lines and counts the occurrences of each unique line
D. Sorts lines and removes duplicates

21 Which command would you use to filter an access log for only entries resulting in a '404 Not Found' error?

A. cat "404"
B. find "404"
C. locate "404"
D. grep "404"

22 What is the primary function of SSMTP in a scripting context?

A. To act as a full-featured mail server like Exchange
B. To send emails from the command line via an external SMTP server
C. To encrypt emails using PGP
D. To receive emails (IMAP server)

23 Which configuration file typically holds the credentials and server details for SSMTP?

A. /etc/ssh/sshd_config
B. /etc/mail/sendmail.cf
C. /var/www/html/config.php
D. /etc/ssmtp/ssmtp.conf

24 To generate a random password, which system file serves as a source of non-blocking pseudorandom data?

A. /dev/urandom
B. /dev/zero
C. /dev/randomness
D. /dev/null

25 In a password generator script, what does tr -dc 'A-Za-z0-9' do?

A. Deletes alphanumeric characters
B. Translates lower case to upper case
C. Encrypts the input
D. Deletes all characters except the complement (alphanumeric)

26 Which command allows you to cut a stream of characters to a specific length (e.g., take the first 12 characters)?

A. head -c 12
B. tail -c 12
C. cut -d 12
D. grep -12

27 What is the fundamental difference between a pipe | and redirection >?

A. > is used for errors only
B. | sends output to a file; > sends output to a command
C. | sends output to another command; > sends output to a file
D. There is no difference

28 If you use >> instead of > when redirecting output to a file, what happens?

A. The command fails if the file exists
B. The output is appended to the end of the file
C. The file is overwritten
D. The file is deleted

29 How do you redirect Standard Error (stderr) to a file?

A. 2>
B. |>
C. 1>
D. &>

30 In the context of automating WordPress setup, what is the purpose of wget https://wordpress.org/latest.tar.gz?

A. To configure the database
B. To update the OS
C. To install Apache
D. To download the WordPress source files

31 Which command is used to extract the .tar.gz file downloaded for WordPress?

A. gunzip latest.tar.gz
B. rar x latest.tar.gz
C. tar -xzf latest.tar.gz
D. unzip latest.tar.gz

32 In a LAMP stack automation script, which user usually owns the web directory (/var/www/html) for security and write access?

A. guest
B. root
C. admin
D. www-data

33 When automating the database setup for WordPress, which SQL command creates the database?

A. NEW DATABASE wordpress;
B. INIT DATABASE wordpress;
C. MAKE DATABASE wordpress;
D. CREATE DATABASE wordpress;

34 To allow WordPress to connect to the database, which file needs to be created from wp-config-sample.php?

A. wp-config.php
B. wp-settings.php
C. config.php
D. wp-connect.php

35 Which sed command pattern is best for replacing a placeholder like database_name_here in a config file?

A. sed -i 's/database_name_here/my_db/' file
B. sed -x 'my_db' file
C. sed 'delete database_name_here' file
D. sed -r 'database_name_here -> my_db' file

36 What is the result of the logical operation cmd1 && cmd2 in a script?

A. cmd2 runs only if cmd1 succeeds
B. cmd2 runs only if cmd1 fails
C. cmd1 runs only if cmd2 succeeds
D. Both commands run simultaneously

37 When using curl to fetch JSON data, how do you suppress the progress meter output?

A. -s
B. -P
C. -v
D. --verbose

38 In a bash script, what does set -e do?

A. Enables syntax highlighting
B. Enables debugging mode
C. Exports all variables
D. Exits the script immediately if a command exits with a non-zero status

39 Which tool would you use to verify that a variable $JSON contains valid JSON syntax before parsing it?

A. validate_json "$JSON"
B. cat "$JSON"
C. echo "$JSON" | jq .
D. echo "$JSON" | grep json

40 When creating a log summarizer, which awk variable represents the number of fields (columns) in the current line?

A. $$
B. NR
C. NF
D. FS

41 In an interactive menu, how do you create an infinite loop that keeps the menu open until the user chooses to exit?

A. for i in {1..100}; do ... done
B. until false; do ... done
C. repeat ... until exit
D. while true; do ... done

42 How do you securely supply a password to mysql in a script without the prompt interrupting the automation?

A. It is impossible
B. mysql -u user -pPASSWORD
C. Type it manually
D. Use telnet

43 What is the purpose of ssh-copy-id user@host?

A. To copy files securely
B. To copy your public key to the remote server's authorized_keys
C. To duplicate the server ID
D. To copy the SSH daemon to a remote server

44 When using grep, which flag allows you to search using Extended Regular Expressions (like | for OR)?

A. -E
B. -i
C. -x
D. -v

45 In an SSMTP email body, what must usually be the first line to ensure the recipient is displayed correctly in email clients?

A. Hello World
B. From: me@example.com
C. To: recipient@example.com
D. Subject: My Subject

46 Which of the following generates a random 16-character string using openssl?

A. openssl random 16
B. openssl sha256
C. openssl rand -base64 12
D. openssl genrsa 16

47 If you want to debug a script by printing every command before it is executed, how do you run the script?

A. bash -e script.sh
B. bash -x script.sh
C. bash -d script.sh
D. bash -v script.sh

48 When automating the Apache service, which command ensures Apache starts automatically when the server boots?

A. service apache2 run
B. systemctl start apache2
C. apache2 --init
D. systemctl enable apache2

49 Which mathematical operator in a Bash arithmetic expansion a ? $b)) performs the modulo operation?

A. /
B. *
C. #
D. %

50 In a JSON API response, if a key contains a special character (e.g., user-name), how must it be referenced in jq?

A. ."user-name"
B. .user-name
C. .['user-name']
D. Both B and C