10D Identify Basics of Scripting

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

You are developing a Bash script to test whether a given host is up. Users will run the script in the following format: ./ping.sh 192.168.1.1 Within the code, what identifier can you use to refer to the IP address passed to the script as an argument?

$1 will refer to the first positional argument.

What command can be used in Bash to restart a Linux machine?

'shutdown -r' command in Bash to restart a Linux machine

What is the primary use case for scripting?

- Basic automation -involes performing series of tasks supported by an OS or app via Script

How can a general-purpose language, like Python, be used for automation?8

-python uses OS API to call functions implemented as modules. -prebuilt modules allow python to automate tasks on Windows Linux and macOS

To mitigate these risks, follow these best practices:

1. Apply access and version controls to script source code to prevent unauthorized changes. 2. Scan and test the code for vulnerabilities and errors before deployment. 3. Configure scripts to run with the minimum privileges necessary for the task.

What is an example of an inadvertent system-settings change due to a script?

An accidental Denial of Service (DoS), where a script powers off a system rather than restarting it, or locks out remote access by changing a firewall configuration.

How can you set up automated backups using Windows Task Scheduler or cron in Linux?

Create a script that uses file-copy tools or backup utility functions and schedule it to run automatically using Windows Task Scheduler or cron in Linux.

What are some examples of Get verb cmdlets in Windows PowerShell used to gather information?

Get-NetAdapter (returns properties of network adapters) and Get-WinEvent (returns log data) are examples of Get verb cmdlets in Windows PowerShell.

How can you initiate updates in Windows using PowerShell?

PSWindowsUpdate module, which contains numerous cmdlets for managing the update process in PowerShell.

A Linux administrator is looking at the bash history and sees the command chmod u+x file.sh. What was trying to be done with this command?

Permissions were being set on the script. Remember that in Linux, the script file must have the execute permission set to run.

What are the three commonly used shell coding environments in Windows?

PowerShell, Visual Basic Script (VBScript), CMD interpreter.

How can you restart a Windows machine using PowerShell?

Restart-Computer cmdlet with the -Force parameter to restart a Windows machine using PowerShell

What is robocopy, and how can it be used for backup purposes in a Windows environment?

Robocopy (Robust File Copy) is a command-line utility in Windows used for file copying, mirroring directories, and synchronization. It's especially useful for backing up large numbers of files or large files because it can handle network

What precautions should be taken to minimize the risks of inadvertent system-settings changes caused by scripts?

Test all code in a development environment and ensure that any changes to hosts required to run the scripts are included and updated/monitored through new configuration baselines. Avoid using scripts that can only work by disabling security mechanisms.

Which commands are used in Linux to make file systems available?

The 'mount' and 'umount' commands

What is the convention for a Linux shell script extension?

The convention for a Linux shell script extension is .SH.

What is a key requirement for executing a Linux shell script?

The script file must have the execute permission set to run.

You want to execute a block of statements based on the contents of an inventory list. What type of code construct is best suited to this task?

You can use any type of loop to iterate through the items in a list or collection, but a For loop is probably the simplest.

How can mishandling of resources by a script lead to accidental DoS?

by creating files that deplete disk storage resources, using faulty loop code constructs that do not terminate, or making faulty API calls to other processes causing them to crash.

How can scripts potentially weaken security configurations?

by enabling the script environment, creating port exceptions, or disabling scanning software for successful script execution.

What is the advantage of using a text editor with script support?

can parse the syntax of the script and highlight elements appropriately, which makes the development process more productive.

What are some risks associated with deploying custom scripts, and how can these risks be mitigated?

malware infection, unauthorized code modification, and exploitation of vulnerabilities.

What is the Windows Script Host and how does it relate to JavaScript?

scripting host on Windows systems that supports JavaScript, among other scripting languages. It comprises two executables, wscript.exe and cscript.exe, which can be used to execute JavaScript scripts.

How can you minimize the risks of resource mishandling caused by scripts?

thoroughly testing every script before deployment, monitoring script execution for any issues, and addressing any bugs that were not found during the testing phase.

How can enabling an interpreter for scripting expand the attack surface for threat actors?

threat actors can use such environments (e.g., PowerShell) to craft fileless malware that can evade traditional security measures.

What are glue languages and what is their purpose?

various types of scripting languages that are used to automate and orchestrate functions of multiple different OS and app software, instead of implementing an independent piece of software.

What are the two major versions of Python, and what is the recommendation regarding their usage?

version 2 and version 3. As of 2020, Python 2 is considered end of life (EOL), so it is recommended that scripts be updated to version 3 syntax.

What measures should be taken to ensure proper input handling in scripts and prevent vulnerabilities from being exploited?

1. Validate all input data to ensure it meets expected formats and values. 2. Sanitize input data to remove potentially harmful characters or content. 3. Use secure coding practices, such as parameterized queries and prepared statements, to prevent code injection attacks.

What is the difference between a "For" loop and a "While" or "Until" loop?

A "For" loop is used when the number of iterations is predictable, whereas a "While" or "Until" loop repeats an indeterminate number of times until a logical condition is met.

A user is reviewing a script and comes across the code in one of the lines #until ping -c1 "$1" &>/dev/null. What is the line doing?

A comment line is indicated by a special delimiter. In Bash and several other languages, the comment delimiter is the hash or pound sign ( # ).

What is the difference between a syntax error and a logical error in a script?

A syntax error occurs when the script's syntax is incorrect, preventing the script from running. A logical error occurs when the script runs but produces unintended or unexpected results due to a mistake in the logic of the code.

What is a variable in a script and how are arguments related to variables?

A variable is a label for a value that can change as the script executes. An argument or parameter is a variable that is passed to the script when it is executed.

How can you execute a .EXE setup file in silent mode using a Windows batch file?

Add the path to the installer plus switches, e.g., C:\David\Downloads\setup.exe /S /desktopicon=yes.

What are basic comparison and logical operators, and why are they important in scripting?

Basic comparison and logical operators are used to perform logical tests that resolve to TRUE or FALSE values. These operators are essential for controlling the flow of code in branches and loops, determining which instructions to execute based on specific conditions. Examples of such operators include "==", "!=", "<", ">", "<=", ">=", "&&", and "||".

What are the differences between CPython and PyPy interpreters for Python?

CPython and PyPy are two different Python interpreters. CPython, developed by python.org, is the simplest environment to set up for Windows and is the default and most widely used implementation of the Python programming language. PyPy, developed by pypy.org, is an alternative interpreter that focuses on performance improvements and uses a Just-In-Time (JIT) compiler to achieve faster execution times compared to CPython.

What is the purpose of comments in a script and how are they indicated in Bash?

Comments are used to provide explanations and clarifications within the code, making it easier to maintain and understand. In Bash, comments are indicated by the hash or pound sign (#).

What is the purpose of the Windows PowerShell Integrated Scripting Environment (ISE)?

Integrated Scripting Environment (ISE) is provided by Microsoft for rapid development of PowerShell scripts.

What are three helpful distinctions between types of coding languages?

Shell scripting language: A shell scripting language uses commands that are specific to an operating system. It is mainly used for automating tasks and managing the operating system's functions. Shell scripts are closely tied to the OS they are written for and are not portable across different systems. General-purpose scripting language: A general-purpose scripting language uses statements and modules that are independent of the operating system. This type of script is executed by an interpreter, which implements the language for a particular OS. General-purpose scripting languages are often used for tasks like web development, data manipulation, and automation. They are more portable than shell scripting languages, as they can run on different operating systems with little or no modification. Programming language: A programming language is used to compile an executable file that can be installed to an OS and run as an app. Programming languages are designed to create stand-alone applications and can be used for a wide range of tasks, from building operating systems to web applications and mobile apps. They often offer more extensive libraries and frameworks, as well as better performance and optimization compared to scripting languages. However, they typically require more time and resources to develop and compile the code.

You are developing a script to ensure that the M: drive is mapped consistently to the same network folder on all client workstations. What type of construct might you use to ensure the script runs without errors?

Use a conditional block (If statement) to check for an existing mapping, and remove it before applying the correct mapping.

How can you gather data from the output of a command in Bash?

Use commands like 'ps' or 'df' to gather data, filter it using 'grep', format it with tools like 'awk' or 'cut', and redirect the output to a file.

What commands can be used in Linux to initiate updates?

Use the 'apt-get/apt' or 'yum' commands in a Bash script to initiate updates in Linux.

How can you use a Windows Installer (.MSI) package in a batch file?

Use the 'msiexec' command followed by the path to the .MSI file and switches, e.g., msiexec C:\David\Downloads\install.msi /qn.

How can you map network drives using PowerShell?

Use the New-PSDrive cmdlet to map network drives in PowerShell.

How can you control installation and handle errors using PowerShell instead of a batch file?

Use the Start-Process cmdlet, which offers more options for controlling the installation and handling errors.

What are some examples of resource mishandling by a script?

creating large log files or temp files that deplete disk storage, using a loop code construct that hangs the script, and making a faulty API call to a host browser that causes it to crash.

What is an Integrated Development Environment (IDE) and why would you use one?

development tool that provides autocomplete features to help write and edit code, and debugging tools to help identify whether the script or program is executing correctly. It is used for complex scripts and programming languages.

How do you execute a Linux shell script if a PATH variable has not been configured?

execute it from the working directory by preceding the filename with ./ (for example, ./hello.sh) or use the full path.

What is a shebang line in a shell script, and what is its purpose?

first line of a shell script that designates which interpreter to use, such as Bash or Ksh.

What is the purpose of Python as a scripting and programming language?

general-purpose scripting and programming language used for developing both automation scripts and software applications. Python projects can be run via an interpreter or compiled as binary executables.

net use

performs drive mapping.

What is the purpose of coding?

process of writing a series of instructions in the syntax of a particular language so that a computer will execute a series of tasks.

What is VBScript and what are its default and alternative interpreters?

scripting language based on Microsoft's Visual Basic programming language. It predates PowerShell and is typically used for Windows automation tasks. VBScript files are executed by the wscript.exe interpreter by default, which displays output in a desktop window or dialog. Alternatively, a script can be run with cscript.exe to show output in a command prompt.

What is JavaScript primarily used for and how is it executed in web browsers?

scripting language primarily used for implementing interactive web-based content and web apps. It is executed in web browsers by placing it in the HTML code for a web page, either embedded within the code or loaded from .JS files.

What is Windows PowerShell and what are cmdlets?

scripting language that combines a script language with hundreds of prebuilt modules called cmdlets, which can access and change most components and features of Windows and Active Directory. Cmdlets use a Verb-Noun naming convention.

What is a batch file in the context of the Windows CMD interpreter?

shell script written for the basic Windows CMD interpreter. Batch files use the .BAT extension and are typically used for automating tasks and managing the operating system's functions.

What are branches and loops, and what is their purpose in a script?

structures that allow for conditional execution of code based on logical conditions. Branches execute different sequences of instructions based on the outcome of a logical test, while loops repeat a statement block based on a condition.


Set pelajaran terkait

Chapter 24 (new book) Hors D'Oeuvres

View Set

7 Habits of Highly Effective Teens, concepts

View Set

Chapter 1 - Mental Health and Mental Illness

View Set

Chapter 16 - Autonomic Nervous System and Higher- Order Functions

View Set

Macroeconomics CH 13 -15 homework Questions

View Set

MACRO Chapter 23: CPI and the Cost of Living

View Set

8th Grade Am. History Ch. 11 Sec. 3

View Set

Europe test ( part of final test)

View Set