10
Scripting Overview Administrative Shell Scripting COMP2101 Fall 2017

COMP2101 01 Scripting Overview - GitHub Pages · • In Linux, the command shell is typically bash, current version is 4, 3 is mostly just missing associative arrays • In Windows,

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: COMP2101 01 Scripting Overview - GitHub Pages · • In Linux, the command shell is typically bash, current version is 4, 3 is mostly just missing associative arrays • In Windows,

Scripting OverviewAdministrative Shell Scripting

COMP2101 Fall 2017

Page 2: COMP2101 01 Scripting Overview - GitHub Pages · • In Linux, the command shell is typically bash, current version is 4, 3 is mostly just missing associative arrays • In Windows,

What is Scripting?• Commands can be given to a computer by entering

them into a command interpreter program, commonly called a shell

• Scripting is the act of saving one or more commands to a file for subsequent execution

• Many interactive command interpreters can be run using saved scripts, bash and Powershell are simply examples

• Commands in scripts are generally executed the same as if they were typed by hand into the interpreter

Page 3: COMP2101 01 Scripting Overview - GitHub Pages · • In Linux, the command shell is typically bash, current version is 4, 3 is mostly just missing associative arrays • In Windows,

Why Script?• Insulate a script user from the details

of a task they are performing; create tools for non-administrative users

• Communicate task activities and requirements to the user in a way the user can understand

• Perform checks to ensure the task is properly run and deal with problems that may arise in carrying out the task as requested by the user

Page 4: COMP2101 01 Scripting Overview - GitHub Pages · • In Linux, the command shell is typically bash, current version is 4, 3 is mostly just missing associative arrays • In Windows,

Values of Scripting

• Scripts do not really introduce new capabilities beyond what can be done on the command line, so why save them?

• Avoidance of human error

• The dreaded typo

• Data validation

• Perfect memory

• Output problems recognition

Page 5: COMP2101 01 Scripting Overview - GitHub Pages · • In Linux, the command shell is typically bash, current version is 4, 3 is mostly just missing associative arrays • In Windows,

Values of Scripting

• Simplification of complex tasks

• Sequences reduced to single commands

• Fixed logic

• Multiple scenario handling

• Errors and unexpected results handling

Page 6: COMP2101 01 Scripting Overview - GitHub Pages · • In Linux, the command shell is typically bash, current version is 4, 3 is mostly just missing associative arrays • In Windows,

Values of Scripting• Automation of repetitive

tasks

• Iterating through data to make edits or summarize information

• Evaluating, summarizing, and/or making changes to files, devices, machines

• Dealing with things going wrong while looping

Page 7: COMP2101 01 Scripting Overview - GitHub Pages · • In Linux, the command shell is typically bash, current version is 4, 3 is mostly just missing associative arrays • In Windows,

When to Script• Scripting is commonly done when iterating over

multiple targets

• Scripting is a good way to save complex command option combinations

• Scripting can be used to enforce business policy

• Scripting gives tools to users so they can perform tasks they do not have the knowledge to directly perform, scripts must take this into account

Page 8: COMP2101 01 Scripting Overview - GitHub Pages · • In Linux, the command shell is typically bash, current version is 4, 3 is mostly just missing associative arrays • In Windows,

Shells• In Linux, the command shell is typically bash, current

version is 4, 3 is mostly just missing associative arrays

• In Windows, the command shell is PowerShell, current version is 3, 4, or 5; 6 core is in the works and available for non-Windows platforms

• Shells evolve over time and new features get added, existing features can change, and some features get removed

Shell version can be very important!

Page 9: COMP2101 01 Scripting Overview - GitHub Pages · • In Linux, the command shell is typically bash, current version is 4, 3 is mostly just missing associative arrays • In Windows,

Lab Requirements

• We will be using bash version 4 in this course, the manual page is our primary documentation

• We will be using PowerShell version 5 in this course, the built-in help and Microsoft developer web site are our documentation resources

• Ubuntu Linux is recommended for the bash shell portion of the course, and Windows 10 is recommended for the Powershell portion of the course

Page 10: COMP2101 01 Scripting Overview - GitHub Pages · • In Linux, the command shell is typically bash, current version is 4, 3 is mostly just missing associative arrays • In Windows,

Script Preservation and Versioning

• Using a virtual Linux machine, or physical machine such as a pi, netbook, or laptop will save your files, but not necessarily protect them

• Consider using github.com to save your files and provide version history for any serious work

https://git-scm.com/book/en/v2