Sub topic 1
Why technicians script
Prerequisites
This chapter assumes you can use the Windows command prompt and a Linux shell for basic tasks such as listing files and changing folders. It also assumes you know what an IP address, a port, and a file path are. No programming experience is required.
What scripting means
A script is a text file that holds a list of commands. An interpreter, such as the Windows command processor, PowerShell, Bash, or Python, reads the file and runs the commands in order. You write the steps once and run them as often as you need.
Automation is the broader goal: getting a computer to do a task without a person typing each step. A script is the most common way a technician does that.
Why technicians script
Support work has many tasks that repeat. A script helps in four ways:
- Speed. One script can finish in seconds what takes minutes by hand.
- Consistency. The same commands run the same way every time. This avoids missed steps and typing mistakes.
- Scale. The same script can run on 5 computers or 500.
- Documentation. The script file records exactly what was done.
The exam links scripting to tasks such as mapping network drives, running backups, gathering system information, installing software, and restarting services. A later chapter covers these use cases in detail.
A first look
The script below is a short Bash example. It records the date, the current user, and the computer's name in a log file.
#!/bin/bash
# Record who ran this script, and when, on which computer
echo "$(date) - user $USER on $(hostname)" >> "$HOME/support-log.txt"The first line, called a shebang, tells Linux which interpreter to use. The second line is a comment, which the interpreter ignores. The third line runs three commands and appends the result to a file. Run it several times and the file grows by one line each time.
The same idea works in every scripting language. Only the syntax changes.
How a script runs
Common mistakes
- Running a script you have not read. A script runs with your permissions. If you are an administrator, it can change anything you can change.
- Skipping a test run. Try a new script on one test machine before you use it on many.
- Hard-coding values. Typing a user name or path into many places makes the script hard to reuse. Later chapters show how variables solve this.
Where this leads
The next chapters teach you to recognize script types by file extension, then to read the building blocks: comments, variables, data types, loops, and conditionals. The second half of the tutorial moves to remote access, where scripts often run on machines you are not sitting in front of.
Exercise
Name two benefits of using a script instead of typing the same commands by hand on each computer.
Show answer
Any two of these: it saves time, it gives the same result every time (consistency), it works on many computers (scale), and it leaves a record of what was done.
Exercise
In the Bash example, what is the purpose of the line that starts with #! and what does the line that starts with # followed by a space do?
Show answer
The #! line (shebang) names the interpreter, /bin/bash, that should run the file. The line starting with "# " is a comment. The interpreter ignores it and it only explains the script to human readers.