Automation and Scripting

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which of the following best describes the role of an agent in software orchestration? A. An agent is software that listens for and executes commands from the server. B. An agent is used to migrate from one operating system to another. C. An agent is a hardware-based token used for authentication. D. An agent is not used in software orchestration

A. An agent is software that runs on clients and listens for commands from the server in an orchestration architecture

Which exit code indicates success for a bash script? A. 0 B. 1 C. 2 D. EOF

A. An exit code of 0 indicates that the script did not encounter an error. This exit code is generally associated with a successful execution of a program in Linux.

You need to create a new empty git repository called repo. Which of the following sequences accomplishes this task? A. mkdir repo; cd repo; git init --bare B. mkdir repo; git init repo/ C. git init repo -md D. git create repo/

A. Creating a git repository requires creating the directory, changing the current working directory to the new directory, and then running git init --bare. The other commands will not create an empty git repository

What characters are used to mark a sequence of commands as a function within a shell script? A. Parentheses to declare the function (optional), and curly braces to contain the commands B. Curly braces to declare the function, and parentheses to contain the commands C. Square brackets to declare the function, and curly braces to contain the commands D. Run quotes to denote the function

A. Parentheses are used to denote a function, such as myFunction(). The parentheses are optional but are then followed by curly braces containing the commands to be executed when the function is called.

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? A. Precede the command with ! and then the string to search for. B. Search for the command in history. C. Precede the command with a ? and then the string to search for. D. This is not possible with bash

A. Preceding the command with a ! will search history and execute the specified command. For example, !vi will start your last vi session.

Which of the following commands produces the output sit sat set? A. echo s{i,a,e}t B. echo s(i,a,e)t C. echo s[i,a,e]t D. echo s/i,a,e/t

A. Shell expansion, or, more accurately, brace expansion, can be used to create the output shown. The other options will not produce output as shown.

Which character sequence is used to execute a command within a subshell in a bash script? A. $() B. subs() C. $% D. $(~

A. The $() sequence executes a command within a subshell, which is helpful for ensuring that global variables in a Bash script cannot be modified. The other sequences shown are not valid for the scenario described

Which option to the git config command shows all of the configuration parameters that have been set? A. --list B. --show C. -u D. --display

A. The --list option shows the current configuration parameters for git. The other options do not exist as options for the git config command.

You are committing code to a git repository and need to include a message on the command line. Which option enables this behavior? A. -m B. -h C. -f D. -l

A. The -m option enables a message to be included in the commit, thereby alleviating the need to go into an editor to create the commit message. The other options shown do not accomplish the required task.

Which option to the declare command will create a variable that is read-only? A. -r B. -ro C. -p D. -x

A. The -r option to declare will create or mark the variable as read-only. The -p option prints output in a format that can be reused. The -x option declares the variable for export

Which environment variable can be used to change the default path for a new git repository created with git init? A. GIT_DIR B. GIT_HOME C. GIT_DEST D. GIT_LOC

A. The GIT_DIR environment variable can be used to change the default location away from the ./.git directory in which a new repository would normally be created. The other options are not used by git as environment variables.

Which escape sequence is used to denote the alert or bell? A. \a B. \b C. \c D. \d

A. The \a escape sequence, when used with the echo command, sounds an alert or bell. The \b option is a backspace. The \c option indicates that echo should not produce any additional output. There is no \d option for echo.

Which git command is used to retrieve a repository from a remote server? A. clone B. checkout C. co D. retr

A. The clone command retrieves a copy of the repository for local use. The checkout and co commands are used with Subversion and not with git

Determining the version of software installed on each client node is an example of collecting information for which collection in an automated infrastructure?

A. The inventory of an infrastructure contains things like the version of software installed on clients.

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? A. DATE="$(date +%s)" B. DATE="date" C. DATE="$(date)"; D. DATE="$date %s"

A. The provided answer performs command substitution and places the value from the resulting command into a variable. Note the use of +%s formatting on the date, which then formats the output as seconds since the epoch, as specified in the question. Option C will provide the date within the DATE variable but will not format it as specified

Which command can be used to add functions and variables to the current shell? A. source B. echo C. en D. src

A. The source command adds functions found in the file argument to the current shell. The source command is frequently used for software installs to ensure that the environment is set up properly prior to execution of the install scripts.

Which shell built-in command can be used to determine the location from which a given command will be run? A. type B. when C. find D. help

A. The type built-in command returns the location that the shell will use in order to run the given command. The find command cannot be used for this purpose, and the other commands do not exist

You are writing a while loop in a bash script and need to compare two string values. Which operator is used for this purpose? A. -ne B. = C. equal D. eq

B. A single equal sign is used for string comparison in a Bash script. Of the other answers, -ne is valid but is used when comparing integers. The string eq would be an operator if preceded by a single dash, as in -eq. In that case, -eq is used for integer comparison.

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? A. if [ $exit -eq "exit" ] B. while true; do C. for ($i = 0, $i++) D. continue until ($exit)

B. A while loop that evaluates boolean true will accomplish the task described. The other options given are syntactically incorrect in various ways

Compiling software when a developer commits code to a certain branch in a repository is an example of which type of automation? A. Infrastructure B. Build C. Complex D. DevOps

B. Build automation is the most appropriate name for kicking off the compilation of software on commit

A. The provided answer performs command substitution and places the value from the resulting command into a variable. Note the use of +%s formatting on the date, which then formats the output as seconds since the epoch, as specified in the question. Option C will provide the date within the DATE variable but will not format it as specified

B. In shell scripts, the commands to execute begin at the do keyword and end at the done keyword. Other languages generally use either curly braces or tabs.

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? A. Security B. Automated configuration management C. Development configuration management D. Usability management

B. Managing configuration with orchestration is described in this scenario, so option B is the closest response.

Which option to the chmod command performs a recursive change? A. -re B. -R C. -c D. -v

B. The -R option performs a recursive change to the targets identified by the chmod command. The other options do not perform recursive changes for chmod.

B. The pipe character sends, or pipes, the output from one command into another and is commonly used in a Linux environment for creating complex command sequences, whether through scripting or directly on the command line. The other options shown are not used for the purpose described in the scenario

B. The -n option suppresses the trailing newline character from the echo command and is quite useful in scripting scenarios. The other options are not valid for the command

Which option is used with the env command in order to remove a variable from the environment? A. -r B. -u C. -n D. -d

B. The -u option or --unset will remove a variable from the environment. The other options are not valid with the env command

Which of the following files is used within a git repository in order to indicate files and file patterns that should not be versioned? A. novers B. .gitignore C. gitignore.txt D. gitnover

B. The .gitignore file is used to store files that will not be versioned

Which character sequence is used to add a horizontal tab using echo with a bash script? A. \h B. \t C. \a D. \f

B. The \t escape sequence adds a horizontal tab. The other characters may have different meaning and so are not valid for this question. For example, \a is alert or bell

Which character sequence indicates the end of an if conditional in a bash script? A. } B. fi C. end D. endif

B. The character sequence fi, which is the if statement backward, indicates the end of an if conditional within a Bash script. The other sequences shown as options may be used in other languages

Which of the following commands displays the current path in bash? A. echo PATH B. echo $PATH C. echo $CURPATH D. ext $PATH

B. The current contents of the PATH variable, or any other shell environment variable, can be displayed using the echo command. Variables in Bash use a $ as part of the identifier. Therefore, any option without the $ would not work.

Which of the following commands removes an environment variable that has been set? A. profile --unset B. env -u C. set -u D. import

B. The env -u command will unset an environment variable for the current session. The unset command can also be used for this purpose.

Which of the following commands changes the location to which HEAD is pointing with git? A. git point B. git checkout C. git change D. git load

B. The git checkout command switches the working copy to the specified branch and points the HEAD toward that branch. The other commands shown as options are not valid with git

Assuming a remote name of origin, which git command can be used to obtain additional information about the remote? A. git show origin B. git remote show origin C. git show remotes D. git remote list

B. The git remote command will be used for this purpose; and, when given the show option and the remote name (origin, in this case), additional information about that remote will be displayed. The command is useful for displaying information about the destination for pushed code

Which of the following commands will display the last 50 lines of your command history when using bash, including commands from the current session? A. bashhist 50 B. history 50 C. cat .bash_history D. tail -f .bash_history

B. The history command will display your command history, including commands from the current session. You can specify how many lines of history to display, as shown in the answer for this question. Note that .bash_history will not show the current session's history

You need to use the output from a command as input for another command. Which character facilitates this scenario?

B. The pipe character sends, or pipes, the output from one command into another and is commonly used in a Linux environment for creating complex command sequences, whether through scripting or directly on the command line. The other options shown are not used for the purpose described in the scenario

Which of the following commands can be used to print the contents of the current shell environment? A. echoenv B. printenv C. showenv D. envvar

B. The printenv command can be used to print the contents of the current shell environment such as environment variables. The other options shown are not valid commands.

vWhich shell built-in command is used to display a list of read-only variables? A. ro B. readonly C. env-ro D. ro-env

B. The readonly command displays the list of read-only variables that have been declared in the current session. The other commands listed for this question do not exist.

Which of the following commands will print a list of six numbers beginning at 0? A. list 0-5 B. seq 0 1 5 C. echo 0-5 D. seq 0 1 6

B. The seq command is used to print a sequence of numbers in a variety of formats. The answer for this question provides a starting point (0), an increment (1), and the final number (5), thus resulting in six numbers being displayed as output

Which of the following terms is used in orchestration and automation scenarios to refer to the collection of devices being managed? A. Device collection B. Inventory C. Machines D. UsableObjects

B. The term inventory is most often used in orchestration to refer to the collection of devices under management.

When using the test built-in with one argument, what will be the return if its argument is not null? A. false B. true C. unknown D. -1

B. The test built-in will return true and can be used to test for the value existence of a variable not being null. Note that the behavior of the test built-in differs depending on the number of arguments.

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? A. > B. >> C. | D. ^

B. Two greater-than signs append output to the specified destination. Option A includes only one greater-than sign, which overwrites rather than appends output. The pipe character in option C does not send output to a file, and option D does not work for the purpose described.

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)? A. ~/.bash_logout B. /etc/bash.bash_logout C. /home/.bash_logout D. /etc/bash_logout

B. While it's true that every user has a .bash_logout, the file exists in their home directory and therefore can be edited by the user. Therefore, to ensure that the required command is executed at logout, the file /etc/bash.bash_logout must be used.

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? A. The command will execute and send all output to the console. B. The command will not execute. C. The command will execute as if the $() command substitution was used. D. The command will execute and send all output to /dev/null.

C. Command substitution can be accomplished using backquotes or $(). These two methods are substantially but not completely equivalent.

Being able to deploy additional servers in response to high demand or load is an example of which type of automation? A. Build B. Compile C. Infrastructure D. Config

C. Infrastructure automation is the term most closely associated with adding (and removing) servers in response to load and demand.

Which test within a shell script while loop will examine one value to see if it is less than another? A. -less B. -lessThan C. -lt D. -lthan

C. The -lt operator is used to test for "less than" conditions within a script. The other operators are not valid for use in a shell script

Which option to declare displays output in a way that could then be used as input to another command? A. -o B. -n C. -p D. -m

C. The -p option displays declare statements in a way that the commands are fully qualified and could then be used as input for another command, through either piping or redirection to a script

Which environment variable is used when changing directory with the tilde character, such as cd ~ ? A. HOMEDIR B. HOMEPATH C. HOME D. MAILPATH

C. The HOME environment variable, set automatically to the user's home directory, is consulted when the command cd ~ is entered. The other paths beginning with HOME do not exist by default, and the MAILPATH environment variable shown contains a list of locations where mail is checked when using the shell interactively

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? A. <> B. & C. && D. |

C. The double-ampersand metacharacter executes the right-hand command only if the first command exits with a successful exit code. A single ampersand sends the command into the background, thus making option B incorrect. A pipe character executes the second command but does so regardless of the success or failure of the first command, thus making option D incorrect.

Which keyword(s) is/are used to begin an alternate condition within a bash script? A. if B. else if C. elif D. elsif

C. The elif keyword is used to create an alternative execution path within a shell script. The other constructs, such as else if and elsif, are used in other languages.

You need to declare a variable as part of the environment prior to running a bash script. Which of the following commands accomplishes this? A. dec B. create C. export D. get

C. The export command adds a variable to the current environment and is frequently used for the scenario described. The other options are not valid commands.

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? A. grep B. telnet C. file D. export

C. The file command can be used to determine which type of file is being used. This can be particularly helpful for files without extensions, where you are unsure if you should view the contents of the file. Option A, grep, is used to look within files but would not be helpful in this case. The telnet and export commands are not used for this purpose

. 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? A. until B. do C. for D. foreach

C. The for loop should be used for this purpose because it iterates through a list. An until loop would require additional code, thus making it a less-preferable construct for the purpose described. There is no do loop or foreach loop in Bash, thus making those options incorrect.

Which git command displays a short history of commits along with the commit ID? A. showhist B. list C. log D. hist

C. The git log command is used to show a commit history. The other commands shown are not valid with git

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? A. | B. < C. > D. &

C. The greater-than sign is used to redirect output to a file and will overwrite the file if it already exists. The other characters do not fulfill the requirements of this scenario

After fetching changes for a previously cloned git repository, which git command is used to incorporate those changes into the local copy? A. put B. push C. merge D. inc

C. The merge command incorporates changes to a previously cloned git repository. The push command is valid but not used for this purpose. The other commands are not valid.

Which of the following characters or character sequences begins a comment in a bash script? A. /* B. // C. # D. '

C. The pound sign (#) is used to indicate that what follows is a comment and will not be executed for the remainder of the line. The other options are valid comment styles in other languages but not for a Bash script.

Which command within a shell script awaits user input and places that input into a variable? A. exec B. get C. read D. prompt

C. The read command awaits user input and places that input into the specified variable. The exec command is used to execute commands, and the other options are not valid for the purpose described.

C. The HOME environment variable, set automatically to the user's home directory, is consulted when the command cd ~ is entered. The other paths beginning with HOME do not exist by default, and the MAILPATH environment variable shown contains a list of locations where mail is checked when using the shell interactively

C. The semicolon metacharacter chains multiple commands together but does not use the output from one command as input to the next. If the output needs to be sent into the next command, the pipe character (option D) is used. A single ampersand places a task in the background, thus making option A incorrect; and a greater-than sign redirects standard output, making option B incorrect as well.

Which command is used to read and execute commands from a file in the bash shell? A. run B. execute C. source D. func

C. The source command is used to execute commands from a file. A typical use case is to create functions or variables that are then available for use within the current session. The other commands listed do not exist

Which command can be used to indicate a local variable within a bash script? A. localvar B. ll C. local D. %local%

C. When executed as part of a function, the local command can be used to create a local variable in a Bash script.

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? A. / B. ' C. " D. \

D. A backslash is used to escape characters such as a single quote in a Bash script. The other characters will not achieve the desired result.

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? A. ls -l !p B. ls -l [!p] C. ls -l [^p] D. ls -l [^p]*

D. File globbing is the process of expansion of special characters, which is required for this scenario. In this case, the negation character is the caret, thus making option D correct

Which, if any, file extension is required in order for a bash script to execute? A. .sh B. .bash C. .bat D. No special extension is necessary

D. No special extension is necessary for a Bash script to be executed. The extension .sh shown as an option is a common extension that you will see for shell scripts of any variety, but the extension isn't required

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? A. $me B. $1 C. $myname D. $0

D. The $0 parameter contains the name of the script being called. The other answers do not fulfill the requirements of this scenario.

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? A. #!/BASH B. #!bash C. #!/bash D. #!/bin/bash

D. The character sequence #!/bin/bash invokes the commands that follow as a Bash script.

Which character sequence is used to indicate the default case within a case statement in a bash script? A. () B. *.* C. ** D. *)

D. The closing parenthesis is used to denote a case; when preceded by an asterisk, the default case is indicated.

Which of the following commands will execute a script and then exit the shell? A. run B. source C. ./ D. exec

D. The exec command executes the command given as its argument and will then exit the shell. The source command does not exit the shell.

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?

D. The set command can be used for a variety of purposes to change how the shell environment works. One such option is -C, which prevents output redirection such as that done with > from overwriting a file if the file already exists.

which of the following best describes the concept of infrastructure as code? the management of switches and routers using compiled programs, the management of servers and others systems using scripting, source code management, and automation, the deployment of hardware using agile methodologies, planning for bugs in infrastructure code and allowing time to fix them

Infrastructure as code typically means managing infrastructure components using some of the same tools that developers would use, such as source code management along with programs or scripts and automation for deployments and configuration changes.

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? A. chmod 700 script.sh B. chown +x script.sh C. chmod script.sh +x D. chmod 777 script.sh

The chmod command will be used for this solution. The answer granting 700 enables execute privileges for the owner. The other options have incorrect syntax or inappropriate permissions for the scenario described

which of the following commands can be used to execute a command with a customized environment? set, env, run, crun

The env command executes a command and enables a custom environment for that command execution. The set command changes environment variables but does not change variables for the single command execution, as specified in the scenario. The other options are not valid commands.

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? fetch, pull, retr, get

The pull command in git fetches the changes and incorporates them into the current working copy. The fetch command only retrieves but does not incorporate the changes. The other options are not valid git subcommands.

What is the name of the default branch in a git repository? A. source B. main C. primary D. master

What is the name of the default branch in a git repository? A. source B. main C. primary D. master 47. You need to use th

Which character sequence is used to terminate a case statement in a bash script? A. end B. done C. esac D. caseend

Which character sequence is used to terminate a case statement in a bash script? A. end B. done C. esac D. caseend

what is the more command used for

a command used to display a text file page by page and line by line on the terminal screen

what is the fgrep command used for

a variant of the grep command that does not allow the use of regular expressions.

what is the egrep command used for

a variant of the grep command used to search for files, patterns, using extended regular expressions.

which of the following packages provides orchestration for linux in an agentless manner? Ansible, puppet, automat, vid

ansible is agentless, using SSH and Python for orchestration. puppet does have an agentless mode but typically uses agents for orchestration. the others are not valid orchestration packages

what is the cd command used for?

change directory

what is the diff command used for

command that compares the contents of text files to identify and differences.

what is the tac command used for

command that displays a file on the screen, beginning with the last line of the file and ending with the first line of the file.

what is a head command

command that displays the first set of lines of a text file; by default, the head command displays the first 10 lines

what is the grep command used for

command that searches files for patterns of characters using regular expression metacharacters. the command name is short for global regular expression print.

what is the cat command used for?

command used to display (or concatenate) the entire contents of a text file to the screen.

what is the less command used for

command used to display a text file page by page on the terminal screen; users can then use the cursor keys to navigate the file.

what is the tail command used for

command used to display lines of text at the end of a file; by default, the tail command displays the last 10 lines of the file.

what is the od command used for

command used to display the contents of a file in the octal format

what is the strings command used for

command used to search for and display text characters in a binary file.

what is the pwd command used for?

displays the current directory in the the directory tree

What is the ll command used for?

it is an alias for the ls -l command; it gives a long file listing

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? Echo, lf, sp, varpt

the echo command is used to send output from a bash script. the other options are not valid commands.

What is an absolute pathname?

the full pathname to a certain file or directory starting from the root directory

what is concatenation?

the joining of text together to make one larger whole.

what is a relative pathname?

the pathname of a target directory relative to your current directory in the tree

what are regular expressions

the special metacharacters used to match patterns of text within text files; they are commonly used by text tool commands, including grep

what is the env command used for

used to display a list of exported variables and functions present in the current shell.

what is the set command used for

used to display a list of variables and functions within a shell

what is the echo command used for

used to display or echo output to the terminal screen. it can use escape sequences.

what is the ls command used for?

used to list the files in a given directory

what is the export command used for

used to send variables to subshells.

what are the four most common wildcard meta characters?

~ * ? [ ]


Ensembles d'études connexes

Context and Connotation - Connotation and Denotation

View Set

Course 2/MOD1 -Explore the CISSP security domains, Part 1

View Set

Biology 196 Ex. 4 My Lab and Mastering

View Set

Ch 8 Adaptive Immunity, Ch 9 Alterations in Immunity and Inflammation, Chapter 10: Infection, Ch 11 Stress and Disease

View Set

Earch Science Lesson 3 Study Guide

View Set

A _______ is an educated guess about the outcome of an experiment.

View Set