Chapter 5
Automation and Scripting

THE FOLLOWING COMPTIA LINUX+ EXAM OBJECTIVES ARE COVERED IN THIS CHAPTER:

  • images  5.1 Given a scenario, deploy and execute bash scripts
    • Shell environments and shell variables
      • PATH
      • Global
      • Local
      • export
      • env
      • set
      • printenv
      • echo
    • #!/bin/bash
    • Sourcing scripts
    • Directory and file permissions
      • chmod
    • Extensions
    • Commenting
      • #
    • File globbing
    • Shell expansions
      • ${}
      • $()
      • ``
    • Redirection and piping
    • Exit codes
      • stderr
      • stdin
      • stdout
    • Metacharacters
    • Positional parameters
    • Looping constructs
      • while
      • for
      • until
    • Conditional statements
      • if
      • case
    • Escaping characters
  • images  5.2 Given a scenario, carry out version control using Git
    • Arguments
      • clone
      • push
      • pull
      • commit
      • merge
      • branch
      • log
      • init
      • config
    • Files:
      • .gitignore
      • .git/
  • images  5.3 Summarize orchestration processes and concepts
    • Agent
    • Agentless
    • Procedures
    • Attributes
    • Infrastructure automation
    • Infrastructure as code
    • Inventory
    • Automated configuration management
    • Build automation
  1. You are writing a shell script using bash and need to print the contents of a variable. Which of the following commands can be used to do so?

    1. echo
    2. lf
    3. sp
    4. varpt
  2. Which of the following packages provides orchestration for Linux in an agentless manner?

    1. Ansible
    2. Puppet
    3. Automat
    4. vid
  3. Which of the following commands can be used to execute a command with a customized environment?

    1. set
    2. env
    3. run
    4. crun
  4. Which of the following commands, when used with git, retrieves the latest objects from a repository and attempts to incorporate those changes into the local working copy of the repository?

    1. fetch
    2. pull
    3. retr
    4. get
  5. Which of the following best describes the concept of infrastructure as code?

    1. The management of switches and routers using compiled programs
    2. The management of servers and other systems using scripting, source code management, and automation
    3. The deployment of hardware using Agile methodologies
    4. Planning for bugs in infrastructure code and allowing time to fix them
  6. Which of the following commands changes a file called script.sh such that it can be executed by the owner of the file and no one else?

    1. chmod 700 script.sh
    2. chown +x script.sh
    3. chmod script.sh +x
    4. chmod 777 script.sh
  7. Which command can be used to add functions and variables to the current shell?

    1. source
    2. echo
    3. en
    4. src
  8. Which of the following is the correct method for invoking the bash shell for a script, typically found as the first line of the script?

    1. #!/BASH
    2. #!bash
    3. #!/bash
    4. #!/bin/bash
  9. You need to send output from a command to a log file. Overwriting the contents of the log file is acceptable. Which of the following characters is used to redirect output in such a way as to fulfill this scenario?

    1. |
    2. <
    3. >
    4. &
  10. You need to create a new empty git repository called repo. Which of the following sequences accomplishes this task?

    1. mkdir repo; cd repo; git init --bare
    2. mkdir repo; git init repo/
    3. git init repo –md
    4. git create repo/
  11. Which of the following terms is used in orchestration and automation scenarios to refer to the collection of devices being managed?

    1. Device collection
    2. Inventory
    3. Machines
    4. UsableObjects
  12. You need to print output from a bash script such that single quotes appear in the outputted string. Which character should be used as an escape sequence in order to get the single quotes into the output?

    1. /
    2. "
  13. Which exit code indicates success for a bash script?

    1. 0
    2. 1
    3. 2
    4. EOF
  14. Which of the following commands produces the output sit sat set?

    1. echo s{i,a,e}t
    2. echo s(i,a,e)t
    3. echo s[i,a,e]t
    4. echo s/i,a,e/t
  15. Which of the following characters or character sequences begins a comment in a bash script?

    1. /*
    2. //
    3. #
  16. Which, if any, file extension is required in order for a bash script to execute?

    1. .sh
    2. .bash
    3. .bat
    4. No special extension is necessary.
  17. After fetching changes for a previously cloned git repository, which git command is used to incorporate those changes into the local copy?

    1. put
    2. push
    3. merge
    4. inc
  18. Which of the following best describes the role of an agent in software orchestration?

    1. An agent is software that listens for and executes commands from the server.
    2. An agent is used to migrate from one operating system to another.
    3. An agent is a hardware-based token used for authentication.
    4. An agent is not used in software orchestration.
  19. Being able to deploy additional servers in response to high demand or load is an example of which type of automation?

    1. Build
    2. Compile
    3. Infrastructure
    4. Config
  20. Which command can be used to indicate a local variable within a bash script?

    1. localvar
    2. ll
    3. local
    4. %local%
  21. Which git command is used to retrieve a repository from a remote server?

    1. clone
    2. checkout
    3. co
    4. retr
  22. You need to echo the name of the script back to the user for usage or help output. Which positional parameter can be used for this purpose?

    1. $me
    2. $1
    3. $myname
    4. $0
  23. Which of the following commands can be used to print the contents of the current shell environment?

    1. echoenv
    2. printenv
    3. showenv
    4. envvar
  24. You are writing a while loop in a bash script and need to compare two string values. Which operator is used for this purpose?

    1. -ne
    2. =
    3. equal
    4. eq
  25. You need to create a bash script that will loop continually and perform some commands within the loop. Which of the following lines will accomplish this task?

    1. if [ $exit -eq "exit" ]
    2. while true; do
    3. for ($i = 0, $i++)
    4. continue until ($exit)
  26. Which of the following commands changes the location to which HEAD is pointing with git?

    1. git point
    2. git checkout
    3. git change
    4. git load
  27. You need to declare a variable as part of the environment prior to running a bash script. Which of the following commands accomplishes this?

    1. dec
    2. create
    3. export
    4. get
  28. Which of the following commands displays the current path in bash?

    1. echo PATH
    2. echo $PATH
    3. echo $CURPATH
    4. ext $PATH
  29. Which character sequence is used to execute a command within a subshell in a bash script?

    1. $()
    2. subs()
    3. $%
    4. $(~
  30. You need to make a change to the configuration of the SSH daemon across your infrastructure. Being able to do so from a central server is an example of which type of automation?

    1. Security
    2. Automated configuration management
    3. Development configuration management
    4. Usability management
  31. Which option is used with the env command in order to remove a variable from the environment?

    1. -r
    2. -u
    3. -n
    4. -d
  32. Within a bash script, you need to run two commands, but only run the second command if the first succeeds. Which of the following metacharacters can be used to accomplish this task?

    1. <>
    2. &
    3. &&
    4. |
  33. You need to redirect the output from a command and append that output to a file. Which of the following character sequences accomplishes this task?

    1. >
    2. >>
    3. |
    4. ^
  34. You need to obtain a directory listing of all files and directories except those that begin with the letter p. Which of the following commands accomplishes this task?

    1. ls -l !p
    2. ls -l [!p]
    3. ls -l [^p]
    4. ls -l [^p]*
  35. Which of the following files is used within a git repository in order to indicate files and file patterns that should not be versioned?

    1. novers
    2. .gitignore
    3. gitignore.txt
    4. gitnover
  36. You need to iterate through a directory listing and perform an operation on certain files within it. To accomplish this task, you will be using a bash script and a looping construct. Which looping construct is most appropriate for this purpose?

    1. until
    2. do
    3. for
    4. foreach
  37. You are debugging a bash script written by a different system administrator. Within the script, you see a command surrounded by backquotes, or `. What will be the result of surrounding the command with backquotes?

    1. The command will execute and send all output to the console.
    2. The command will not execute.
    3. The command will execute as if the $() command substitution was used.
    4. The command will execute and send all output to /dev/null.
  38. Which git command displays a short history of commits along with the commit ID?

    1. showhist
    2. list
    3. log
    4. hist
  39. You are committing code to a git repository and need to include a message on the command line. Which option enables this behavior?

    1. -m
    2. -h
    3. -f
    4. -l
  40. Compiling software when a developer commits code to a certain branch in a repository is an example of which type of automation?

    1. Infrastructure
    2. Build
    3. Complex
    4. DevOps
  41. You are working with a MySQL database and need to read in several SQL commands from a file and send them into the MySQL CLI for execution. You will be using STDIN redirection for this. Which of the following commands is correct, assuming a filename of customers.sql?

    1. mysql < customers.sql
    2. mysql | customers.sql
    3. mysql > customers.sql
    4. mysql >< customers.sql
  42. You are collaborating on a coding project using git as the source code management tool. Teammates are saying that they cannot see your code, although you have been committing code regularly. Which of the following is most likely the problem?

    1. You have not added commit messages.
    2. You need to send the commit IDs to the teammates.
    3. You have not executed git push to send the code to the server.
    4. You are committing using the -h flag.
  43. Which option to the chmod command performs a recursive change?

    1. -re
    2. -R
    3. -c
    4. -v
  44. Which character sequence is used to indicate the default case within a case statement in a bash script?

    1. ()
    2. *.*
    3. **
    4. *)
  45. Which character sequence indicates the end of an if conditional in a bash script?

    1. }
    2. fi
    3. end
    4. endif
  46. What is the name of the default branch in a git repository?

    1. source
    2. main
    3. primary
    4. master
  47. You need to use the output from a command as input for another command. Which character facilitates this scenario?

    1. >
    2. |
    3. !
    4. `
  48. Which git command shows the current state of the working copy of a repository?

    1. git list
    2. git status
    3. git state
    4. git view
  49. Which option to the echo command suppresses the ending newline character that is normally included?

    1. -a
    2. -n
    3. -d
    4. -y
  50. Determining the version of software installed on each client node is an example of collecting information for which collection in an automated infrastructure?

    1. Inventory
    2. Group
    3. Procedure
    4. Build
  51. You need to redirect STDERR from a command into a file to capture the errors. Which character sequence can be used for this purpose?

    1. >
    2. %2>
    3. 2>
    4. %%>
  52. You need to make a change to your git environment because your email address has changed. Which of the following commands ensures that your new email address will be used for all subsequent commits?

    1. git config user.email
    2. git change email
    3. git config email.addr
    4. git config email.address
  53. Which shell built-in command is used to display a list of read-only variables?

    1. ro
    2. readonly
    3. env-ro
    4. ro-env
  54. Assume that you’re using the bash shell and want to prevent output redirects from accidentally overwriting existing files. Which command and option can be used to invoke this behavior?

    1. setoutput -f
    2. overwrite=no
    3. overwrite -n
    4. set -C
  55. You have received a file that does not have a file extension. Which command can you run to help determine what type of file it might be?

    1. grep
    2. telnet
    3. file
    4. export
  56. Which of the following commands will display the last 50 lines of your command history when using bash, including commands from the current session?

    1. bashhist 50
    2. history 50
    3. cat .bash_history
    4. tail -f .bash_history
  57. When using bash, how would you execute the last command starting with a certain string, even if that command was not the last one that you typed?

    1. Precede the command with ! and then the string to search for.
    2. Search for the command in history.
    3. Precede the command with a ? and then the string to search for.
    4. This is not possible with bash.
  58. Which shell built-in command can be used to determine the location from which a given command will be run?

    1. type
    2. when
    3. find
    4. help
  59. Which command is used to read and execute commands from a file in the bash shell?

    1. run
    2. execute
    3. source
    4. func
  60. You need a command to be executed on logout for all users. Within which file should this be placed (assuming all users are using bash)?

    1. ~/.bash_logout
    2. /etc/bash.bash_logout
    3. /home/.bash_logout
    4. /etc/bash_logout
  61. Which of the following commands removes an environment variable that has been set?

    1. profile --unset
    2. env -u
    3. set -u
    4. import
  62. When setting the shebang line of a shell script, which of the following commands will help to determine the location of the interpreter automatically?

    1. #!/usr/bin/env bash
    2. #!/bin/bash
    3. #!env
    4. /bin/int bash
  63. Which of the following best describes the PS1 environment variable?

    1. PS1 is used to set the location of the PostScript command.
    2. PS1 is used to define the default shell prompt for bash.
    3. PS1 is used as a per-system variable.
    4. PS1 is user-defined and does not have a default value or setting.
  64. Which variable within a bash script is used to access the first command-line parameter?

    1. $ARG
    2. $0
    3. $1
    4. $ARG0
  65. Which of the following commands will print a list of six numbers beginning at 0?

    1. list 0-5
    2. seq 0 1 5
    3. echo 0-5
    4. seq 0 1 6
  66. Which of the following commands will execute a script and then exit the shell?

    1. run
    2. source
    3. ./
    4. exec
  67. Which command within a shell script awaits user input and places that input into a variable?

    1. exec
    2. get
    3. read
    4. prompt
  68. What characters are used to mark a sequence of commands as a function within a shell script?

    1. Parentheses to declare the function (optional), and curly braces to contain the commands
    2. Curly braces to declare the function, and parentheses to contain the commands
    3. Square brackets to declare the function, and curly braces to contain the commands
    4. Run quotes to denote the function
  69. Which character sequence is used to terminate a case statement in a bash script?

    1. end
    2. done
    3. esac
    4. caseend
  70. Which option to declare displays output in a way that could then be used as input to another command?

    1. -o
    2. -n
    3. -p
    4. -m
  71. Which characters are used to denote the beginning and end of the test portion of a while loop in a shell script?

    1. Parentheses ( )
    2. Curly braces { }
    3. Square brackets [ ]
    4. Double quotes " "
  72. When using the test built-in with one argument, what will be the return if its argument is not null?

    1. false
    2. true
    3. unknown
    4. -1
  73. Which environment variable is used when changing directory with the tilde character, such as cd ~ ?

    1. HOMEDIR
    2. HOMEPATH
    3. HOME
    4. MAILPATH
  74. You would like to examine the entries for a single file through the git commit history. Which command should be used for this purpose, assuming a filename of nhl_scores.php?

    1. git log --history nhl_scores.php
    2. git log --follow nhl_scores.php
    3. git history nhl_scores.php
    4. git commit-history nhl_scores.php
  75. Which of the following best describes attributes of an inventory within an automated infrastructure?

    1. Parameters such as the client IP address and software versions
    2. The number of client nodes
    3. The software used on the server for the orchestration
    4. The architectural pattern for deployment
  76. Which operator should be used when comparing integers to determine if one is equal to another in a bash script?

    1. -ro
    2. ===
    3. -eq
    4. -fe
  77. You would like to run several commands in succession but not have the output sent into the next command. Which of the following metacharacters will accomplish this task?

    1. &
    2. >
    3. ;
    4. |
  78. Which escape sequence is used to denote the alert or bell?

    1. a
    2. 
    3. c
    4. d
  79. Which of the following is a valid variable declaration in a bash script, setting the variable NUM equal to 1?

    1. NUM = 1
    2. $NUM = 1
    3. NUM= 1
    4. NUM=1
  80. Which of the following commands will obtain the date in seconds since the epoch and place it into a variable called DATE within a shell script?

    1. DATE="$(date +%s)"
    2. DATE="date"
    3. DATE="$(date)";
    4. DATE="$date %s"
  81. Which sequence is used to mark the beginning and end of the commands to execute within a for loop in a shell script?

    1. Curly braces { }
    2. The keywords do and done
    3. Semicolons ;
    4. Tabs
  82. Which option to the declare command will create a variable that is read-only?

    1. -r
    2. -ro
    3. -p
    4. -x
  83. Which environment variable controls the format of dates and times, such as a 12-hour or 24-hour formatted clock?

    1. LOCALE_DATE
    2. DATE_FORMAT
    3. LC_TIME
    4. LC_DATE
  84. Which option to netstat displays interface information in a table-like format that might be suitable for use with scripting?

    1. -i
    2. -r
    3. -t
    4. -l
  85. You are running a shell script from within your SSH session. Which key combination can be used to terminate the script?

    1. Ctrl+X
    2. Ctrl+-
    3. Ctrl+C
    4. Ctrl+Esc
  86. Which of the following conditionals in a bash script will test if the variable DAY is equal to SUNDAY?

    1. if ($DAY == "SUNDAY")
    2. if ($DAY -eq "SUNDAY")
    3. if [[ $DAY == "SUNDAY" ]]
    4. if [ DAY = "SUNDAY" ]
  87. Which of the following commands adds ~/code/bin to the path?

    1. PATH=~/code/bin:$PATH
    2. PATH=/code/bin:$PATH
    3. PATH=/home/code/bin:$PATH
    4. PATH=PATH:~/code/bin
  88. Which option to git merge can be used to attempt to roll back a merge that has conflicts?

    1. --rollback
    2. --abort
    3. --rewind
    4. --restart
  89. Which environment variable can be used to change the default path for a new git repository created with git init?

    1. GIT_DIR
    2. GIT_HOME
    3. GIT_DEST
    4. GIT_LOC
  90. Which character sequence is used to add a horizontal tab using echo with a bash script?

    1. h
    2. a
    3. f
  91. You need to exclude a build file, called build.o, from being tracked by git. Which character sequence can be used in the .gitignore file to exclude or ignore that file in all directories?

    1. build.o
    2. /build.o
    3. **/build.o
    4. build.*
  92. Which file-globbing sequence will match all files that begin with an uppercase A or an uppercase F?

    1. [AF]*
    2. [af]*
    3. *AF*
    4. AF*
  93. Assuming a remote name of origin, which git command can be used to obtain additional information about the remote?

    1. git show origin
    2. git remote show origin
    3. git show remotes
    4. git remote list
  94. Which character sequence displays the number of command-line arguments that were passed to a bash script?

    1. $NUM
    2. $CLA
    3. $+
    4. $#
  95. Which environment variable can be set if you wish to automatically log users out of their shell after a certain period of inactivity?

    1. TIMEOUT
    2. TMOUT
    3. TO
    4. IDLETIME
  96. You are debugging a bash script and notice a line that contains: echo $NUM #sending $NUM to output. What will be the result of this line when executed?

    1. It will not output anything, because it is commented out.
    2. It will cause a syntax error, because it is invalid syntax.
    3. It will output the contents of the NUM variable.
    4. It will output the sequence "$NUM".
  97. When cloning a repository with git clone, you need to change the name of the remote so that it is not called origin. Which option can be added to git clone to accomplish this task?

    1. --origin
    2. --remote
    3. --name
    4. --remote-name
  98. When working in a virtual server environment, which column within iostat output shows the amount (percentage) of time spent in an involuntary wait scenario due to the hypervisor?

    1. proc
    2. wait
    3. user
    4. steal
  99. If you need to temporarily reconfigure all locale variables and settings for a given session, which environment variable can be used?

    1. LC_LIST
    2. LC_GLOBAL
    3. LC_ALL
    4. ALL_LOCALE
  100. A set of commands to execute on a client node is an example of which type of infrastructure automation?

    1. Procedure
    2. Subset
    3. Agent
    4. Collection
  101. Which character sequence is used to indicate the end of an individual clause within a case statement in a bash script?

    1. //
    2. ’eol
    3. ;;
    4. <
  102. Which of the following commands removes a currently defined aliased command?

    1. remove
    2. rm
    3. unalias
    4. delete
  103. Which of the following tests will determine if a file exists in the context of a shell script?

    1. -a
    2. -e
    3. -m
    4. -i
  104. Which of the following values for the LANG environment variable will configure the system to bypass locale translations where possible?

    1. LANG=COMPAT
    2. LANG=NONE
    3. LANG=C
    4. LANG=END
  105. Which option to the git config command shows all of the configuration parameters that have been set?

    1. --list
    2. --show
    3. -u
    4. --display
  106. Which character sequence should be used if you need to redirect STDERR to a file and append to the file?

    1. 2>
    2. 2>>
    3. &>>
    4. 1>>
  107. When working with infrastructure as code, you have received a file with a .yml extension. What is the likely format for the contents of this file?

    1. YAML
    2. XML
    3. Tab-delimited
    4. Text
  108. Which of the following best describes the result of the command cat /etc/passwd | cut -d: -f1 > users.txt?

    1. The first field will be extracted from the passwd file and placed into a file called users.txt.
    2. The second field will be extracted from the passwd file and placed into a file called users.txt.
    3. The passwd file will be separated based on a colon and output placed into users.txt.
    4. The passwd file will be sent to the terminal where only fields beginning with a colon will be shown and placed into a file called users.txt.
  109. Which shell built-in can be used to move positional parameters down, where $2 becomes $1, $3 becomes $2, and so on?

    1. move
    2. rev
    3. shift
    4. dec
  110. You are using git pull to obtain changes to a shared repository. Which option should you add to git pull in order to prevent autocommit so that you can look at the results of the merge first?

    1. --pre-merge
    2. --no-auto
    3. --nc
    4. --no-commit
  111. Which of the following pairs indicates the beginning and end of an until loop in a bash script?

    1. do; done
    2. start; stop
    3. beg; end
    4. until; litnu
  112. Which exit code is used to indicate a general error within a bash script?

    1. 0
    2. 1
    3. 255
    4. -1
  113. When scripting for build automation, you need to run a configure script prior to running the make command. Which of the following will execute the configure script, assuming that it’s in the same directory as the script invoking it?

    1. configure
    2. ./configure
    3. ../configure
    4. /configure
  114. Assuming that a file has been previously added and committed to git, which option to the git commit command can be used to automatically add and commit the file?

    1. -a
    2. -b
    3. -c
    4. -d
  115. Which locale-related environment variable is used for currency-related localization?

    1. LC_MONE
    2. LC_CURRENCY
    3. LC_MONETARY
    4. LC_CURR
  116. Which of the following lines added to .profile in a user’s home directory will set their time zone to Central time?

    1. TZ=/Central ; export TZ
    2. TIMEZONE=’America/Chicago’ ; export TIMEZONE
    3. set TZ=/Central
    4. TZ=’America/Chicago’; export TZ
  117. Which of the following creates an array in a bash script?

    1. ARRAY=(val1 val2)
    2. ARRAY = "val1 val2"
    3. ARRAY_PUSH($ARRAY,"val1","val2");
    4. ARRAY{0} = "val1"
  118. Which test within a shell script while loop will examine one value to see if it is less than another?

    1. -less
    2. -lessThan
    3. -lt
    4. -lthan
  119. Assuming that a space-separated list of values has been defined as LIST="one two three four", which of the following for loop constructs will iterate through the elements in the list?

    1. for LIST
    2. for VAR in LIST
    3. for VAR in $LIST
    4. for $LIST -> $VAR
  120. Which keyword(s) is/are used to begin an alternate condition within a bash script?

    1. if
    2. else if
    3. elif
    4. elsif
  121. Within which directory does git store a local copy of the repository metadata?

    1. .gitmeta
    2. gitlocalmeta
    3. .git
    4. git
  122. You need to redirect both STDERR and STDOUT to a file. Which of the following character sequences accomplishes this task?

    1. 2>
    2. 2>&1
    3. 2+1
    4. +2+1
  123. Within a bash script, you need to run two commands, but only run the second command if the first fails. Which of the following metacharacters can be used to accomplish this task?

    1. <>
    2. &
    3. &&
    4. ||
  124. Which of the following commands creates a new branch called project1 and points the HEAD toward that branch?

    1. git branch project1
    2. git checkout project1
    3. git checkout -b project1
    4. git create project1 -H
  125. Which of the following best describes the difference between a while and an until loop in a bash script?

    1. A while loop always executes once; an until loop does not.
    2. An until loop always executes once; a while loop does not.
    3. A while loop executes as long as a condition is true; an until loop executes until the condition is false.
    4. An until loop executes until a condition is true; a while loop executes until a condition is false.
  126. Which statement can be used in a bash script to determine if variable $num1 is greater than $num2, assuming both variables contain integers?

    1. if [ "$num1" -gt "$num2" ]
    2. if [ "$num1" > "$num2" ]
    3. if ($num1 -gta $num2)
    4. if [ $num1 gt $num2 ]
  127. Which of the following protocols is typically used for agentless infrastructure orchestration?

    1. SMTP
    2. ICMP
    3. SSH
    4. FTP
  128. Which of the following character sequences expands or interpolates a variable called VAR within a bash script?

    1. VAR
    2. $(VAR}
    3. ${VAR}
    4. *VAR*
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.38.125