Upload
others
View
5
Download
0
Embed Size (px)
Citation preview
Scripting OverviewAdministrative Shell Scripting
COMP2101 Fall 2017
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
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
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
Values of Scripting
• Simplification of complex tasks
• Sequences reduced to single commands
• Fixed logic
• Multiple scenario handling
• Errors and unexpected results handling
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
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
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!
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
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