Introduction to scripting

Submitted by coleen.yan@edd… on Mon, 04/15/2024 - 16:37

Scripting for systems administrators refers to the process of writing and executing scripts to automate tasks and manage computer systems. Using programming or scripting languages, systems administrators create a series of one or more instructions that can be executed by a computer to perform specific actions. Scripting is an integral part of system administration because of its efficiency, flexibility, and ability to handle repetitive tasks.

Automating routines and time-consuming tasks is one of the primary reasons scripting is important in systems administration. Administrators often find themselves performing repetitive actions such as creating user accounts, configuring network settings, installing software, and monitoring system resources. By scripting these tasks, administrators can save significant amounts of time and effort. Developing scripts that automate these tasks, allows them to focus on more complex and critical aspects of system management.

Scripting plays a vital role in extending the functionality of software applications. Many development frameworks and platforms provide scripting interfaces or application programming interfaces (APIs) that allow developers to customize and enhance existing applications. By writing scripts, developers can create plugins, add-ons, or extensions that introduce new features, integrate with other systems, or automate repetitive tasks. Scripting enables developers to tailor software to specific requirements and extend its capabilities without the need for extensive modifications or recompilation.

Different scripting languages are used in different situations. The languages used in things such as web development, database administration, or game development are all specific and developed for those purposes. These specialized scripting languages provide libraries, frameworks, and tools that are tailored to the needs of their respective domains. For instance, web developers often use scripting languages like JavaScript to create interactive user interfaces, manipulate the Document Object Model (DOM), and communicate with servers asynchronously.

Sub Topics

Software refers to computer programs that run on devices like PCs, mobile phones, and tablets. It includes scripts, applications, programs, and sets of instructions that make a computer work. For example, operating systems, diagnostic tools, video games, and apps are all types of software.

The concept of software was introduced by Alan Turing in 1935, but the term itself was coined by John Tukey in 1958. Software is categorized into four main types:

  1. Programming software: These are tools that help developers write programs. Examples include compilers, debuggers, and text editors.
  2. System software: This serves as the foundation for application software. It includes device drivers, operating systems (OSs), and utilities that make the computer run smoothly.
  3. Application software: This is software designed for specific tasks, such as office suites, games, databases, and educational programs. It can be a single program or a collection of smaller programs.
  4. Malicious software (malware): This type of software is created to harm computers and disrupt other software. It often works secretly and can include spyware, viruses, trojan horses, worms, and adware.

 

Software is essential for a computer to function. Different types of software rely on each other. For example, an application software like a word processor needs an operating system to run, and the operating system itself is developed using programming software.

To use software, it must be installed on a computer or smartphone. This can be done by copying it from a physical storage device (like a CD or DVD) or downloading it from the internet. When no longer needed, software can be uninstalled, although some malware may require additional software, like antivirus programs, to be removed.

Software can be purchased online or in stores, but there are also free options available. Trial versions and shareware allow users to test software for a limited time or number of uses before deciding to purchase it. Freeware and open-source software can be used without cost, with open-source software even allowing users to modify and improve the program's source code.

Important Note: As an IT professional you have an ethical responsibility to ensure that all software being installed is licenced appropriately. The cost of developing the software has to be paid somehow by either watching ads or by paying for a licence. There are a few developers who develop good software as a hobby and do not get paid for it, but there are not many who do that. To install licenced software without paying for it is theft.

This course is focused on managing system software using scripts. This includes Hyper-V, system settings apps, and ways to control and configure operating systems.

All scripting languages are programming languages. However, not all programming languages are scripting languages.

A 'scripting language' is essentially a language in which instructions for a run-time environment are written and interpreted by the system, rather than needing to be compiled.

Scripting languages are computer languages used to add additional functionality to apps and connect complex systems; i.e. intended to integrate and communicate with other programming languages.

Some common scripting languages include:

  • Bash: A scripting language designed for use with the Linux interface. Bash is far more user-friendly than other programming languages for creating scripts. It discusses the tools to use and codes in the command line, how to create useful reusable scripts and save documentation for others to use.
  • Ruby: There are numerous reasons to learn the Ruby programming language. Ruby's adaptability has enabled developers to design cutting-edge software. It's a scripting language that's excellent for web development.
  • Python: Simple, free and open source. Python supports both procedure-oriented and object-oriented programming. Python is the most popular programming language among developers because it is an interpreted language with dynamic semantics, allowing vast quantities of code to be written.
  • Perl: A scripting language with unique characteristics that set it apart and make it popular. All Windows and Linux servers have it. It is useful for text manipulation tasks.
  • PowerShell:A modern command shell that includes the best features of other popular shells. It is a cross-platform (Linux, Windows, and Mac) command-line shell and scripting language built for task automation and configuration management. Unlike most shells that only accept and return text, PowerShell accepts and returns .NET objects. It includes robust command-line history, tab completion and command prediction.

Some of the prominent characteristics of scripting language are:

  • open-source, meaning users can have full access to view and edit code
  • comparatively faster to develop than compiled applications
  • a limited number of data structures makes it easy to write and edit
  • useful for creating new applications in web browsers
  • can be used to create plug-ins and extensions for other applications.

Interpreted vs. compiled

As stated above, scripting languages are 'interpreted' rather than 'compiled'. But what is the difference?

Code that is written in a compiled language like C, C++ or C#, cannot be directly executed by a computer. Compiling means that the language is reassembled into low-level machine-readable instructions that the computer can then execute.

You cannot read a compiled program’s written code.

A diagram depicting the difference between compiled and interpreted languages

Compiled programs often run faster than interpreted ones; however, code written in interpreted languages can be modified while the program is running.

Examples of compiled languages include:

  • C
  • C++
  • Go
  • Fortran
  • Pascal.

Examples of interpreted languages include:

  • Python
  • PHP
  • Ruby
  • JavaScript.

Activity

Let's create a script.

  1. Open Notepad.
  2. Enter the commands shown below:

  3. Save to your desktop as “today.cmd” (you will need to make sure has extension .cmd and not .txt). 
  4. You should have a new icon on the desktop with cogs.
  5. Double click the icon. Notepad will open displaying the current date. 
  6. At the command prompt use the time /? command to see if you can:
    1. add the current time to the above script.
    2. Explain the significance of the /t in the date command.
    3. What the role of the '>' is in the command.

For more on scripting see the CompTIA e-book (Topic 19D: Identify Basics of Scripting).

Advantages of scripts

  • Open-source, allowing users to view and edit the script if needed.
  • Does not require the file to be compiled, but may be when necessary.
  • Easy to learn and write.
  • Easy to port between different operating systems.

Disadvantages of scripts

  • Open source allows others to view source code, which may be prohibited by some companies.
  • Requires the user to install an interpreter or separate program before the script can be run.
  • In some situations, they may be slower than a compiled program.
Compiled Interpreted
Pros Cons Pros Cons
Ready to run Not cross-platform Cross-platform Interpreter required
Often faster Inflexible Simpler to test Often slower
Source code is private Extra step Easier to debug Source code is public

 

A developer coding in their preferred IDE, on their laptop and additional displays

What is an IDE?

An Integrated Development Environment (IDE) is essentially software for developing software…confusing, right?

An IDE typically combines the 3 main tools necessary for software development:

  1. A source code editor: Basically a fancy text editor. These often include productivity features like syntax highlighting, auto-completion and visual indications for issues and bugs.
  2. A runtime environment: A way of executing code without having to compile it. This is particularly important when using compiled languages because compiling an application every time you want to test something can be time-consuming and tedious.
  3. A debugger: A tool for finding and fixing bugs in the source code before compiling.

Scripting languages often don’t require the use of an IDE. Because the code is interpreted, the run-time environment is usually already present on the computer and debugging is done during run-time.

Popular IDEs

Visual Studio

Visual Studio (VS) is a full-featured development environment, available for Windows and Mac OS platforms. There are 3 different versions of VS provided. The 'Community' version is free for individual developers, while the 'Professional' and 'Enterprise' versions of the IDE require a licence.

PhPStorm

PhPStorm is an IDE focused on the creation of front-end code and applications using the programming language, PHP; although it also supports the use of more languages like JavaScript, CSS, HTML5, Sass, Less and others. JetBrains’ PhPStorm can be integrated with other website creation software and platforms like WordPress, Laravek, Joomla and Drupal. Similar to the other products in the JetBrains product suite, it comes with code suggestions, testing tools and debugging tools.

XCode

XCode is a free, open-source IDE. XCode provides tools for the creation of applications for Apple devices including the Mac, iPhone and iPad. XCode integrates with the CocoaTouch development framework for iPhones and iPads. It lets you enable features like Passbook or Game Center with just the click of a button and supports a split-screen workspace (even letting you build prototypes using the Interface Builder).

Check your knowledge

Answer these three questions about programming and scripting. 

Module Linking
Main Topic Image
A laptop displaying a developer's IDE, showing functions the devloper has just authored
Is Study Guide?
Off
Is Assessment Consultation?
Off