0% found this document useful (0 votes)
2 views18 pages

Server Scripting

The document discusses the role of shell scripting and automation in Linux, highlighting various types of shells such as Bourne, Bash, C Shell, Korn, and Z Shell, each with unique features and functionalities. It also explains the cron tool for job scheduling, detailing its purpose in automating tasks and the management of cron jobs through the crontab file. Additionally, it touches on server automation on Windows platforms, specifically focusing on PowerShell for managing scheduled tasks.

Uploaded by

Bernard Masina
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views18 pages

Server Scripting

The document discusses the role of shell scripting and automation in Linux, highlighting various types of shells such as Bourne, Bash, C Shell, Korn, and Z Shell, each with unique features and functionalities. It also explains the cron tool for job scheduling, detailing its purpose in automating tasks and the management of cron jobs through the crontab file. Additionally, it touches on server automation on Windows platforms, specifically focusing on PowerShell for managing scheduled tasks.

Uploaded by

Bernard Masina
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Server Scripting and Automation

Group 5
The role of the shell as a scripting and automation
environment

A shell is special user program which provide an interface to user to use


operating system services.
A shell script is a text file that contains a sequence of commands in a language
that can be interpreted by the shell.
Automation the technique of making an apparatus, process or system operate
automatically
The role of the shell

 System administrators can use shell scripting to automate administrative tasks like user
account creation, system status monitoring
 Shell scripting can also be used for routine backups,
 adding new functionality to the shell,
 automating the code,
 compiling process
 linking existing programs together.
Different Types of Shells in Linux

1. The Bourne shell (sh)


 Named after its creator Stephen Bourne.
 It became the default command-interpreter in Unix because of its support for command
substitution, piping, variables, condition testing, and looping. It also executes its operations at a
high speed.
 Its path is /bin/sh and /sbin/sh.
 However, the Bourne shell has some major drawbacks.
 It did not offer much customization for users,
 didn’t support such modern niceties such as aliases, command completion, and shell functions.
 It doesn’t have in-built functionality to handle logical and arithmetic operations. Bourne shell cannot
recall previously used commands
Shells continued…

2. The GNU Bourne-Again shell (bash)


 It incorporates useful features from different types of shells in Linux such as Korn shell and C
shell.
 The complete path-name for the bash shell is /bin/bash.
 Bash shell allows us to automatically recall previously used commands and edit them with
help of arrow keys, unlike the Bourne shell.
Shells continued…

3. The C Shell (csh)


 Created by Bill Joy at the University California.
 It was developed to include useful programming features like in-built support for arithmetic
operations and a syntax similar to the C programming language.
 Another important feature is that is has command history and also includes “aliases”.
 Even though it is an improvement compared to the Bourne shell the C shell is slower than
Bourne shell.
 The complete path is /bin/csh
Shells continued…

4. The Korn (ksh)


 It was made to improve the Bourne shell.
 Besides supporting everything that would be supported by the Bourne shell, it provides
users with new functionalities.
 It allows in-built support for arithmetic operations while offering interactive features which
are similar to the C shell.
 It also supports scripts which were written for the C shell.
 Further, it is faster than most different types of shells in Linux, including the C shell.
Shells continued…

5. The Z shell (zsh)


 This is one of the most popular newer shells Zsh is a Bourne-style shell that contains the
features you’ll find in bash, plus even more
 For example:
 zsh has spell-checking,
 the ability to watch for logins/logouts,
 allows for floating-point arithmetic,
 generate filenames based on given conditions,
 global aliases.
 The path is /bin/zsh
The structure and general syntax ctn’d

 functionname() {
shell commands }

 Variables has the following syntax


 VARNAME = value;
The role of the cron tool in Linux/Unix

 In any OS it is possible to create jobs that you want to reoccur this process is called job
schedulling.
 This process is handled by cron service called chrond. (runs a process at interval)
 Linux distros come with predefined jobs by default. syst admn can define tasks, schedule
such processes to run automatically in the background at regular intervals of time.
 According to [Link], cron tool is a software utility that automates the
scheduled task at a predetermined time.
 It is a daemon process
Role of the cron ctn’d

 The following are the roles of the cron tool:


 It enables the users to execute the scheduled task on a regular basis unobtrusively eg:
❖ doing the backup every day at midnight,
❖ scheduling updates on a weekly basis,
❖ synchronizing the files at some regular interval.
 Cron checks for the scheduled job recurrently and when the scheduled time fields match
the current time fields, the scheduled commands are executed.
 It is started automatically from /etc/init.d
The function of the crontab file

 The crontab (abbreviation for “cron table”) is a file that manages the cronjob.
 It consists of a list of commands one per line that will be executed at regular intervals.
❑ Crontab allows the user to add, remove or modify the scheduled tasks.
❑ It is also responsible for managing routine tasks such as scheduling a system scanning or running
daily backup.
 To open a crontab we use a command crontab -e. once opened you can create a
cronjob.
The crontab command syntax
The crontab command syntax cnt’d
 The asterisk (*) on a field stands for all the values of the field. For instance, to execute a
command daily, we can put an asterisk(*) in the week’s field.
 One can also use a range of numbers, separated with a hyphen (-) in the time and date field to
include more than one contiguous value.
 The comma (,) operator is used to include a list of numbers which may or may not be
consecutive. For example, “1, 3, 5” in the weeks’ field signifies execution of a command every
Monday, Wednesday, and Friday.

 Example: 30 7 1 * * /path/delete_logs.sh > /dev/null 2>&1



 The cron job above is going to be running on the 1st of every month at 7:30 AM and will delete
files that are older than 30 days.
Reflection!!!!!

Run the backup script /[Link] every Sunday


midnight 12 AM.
General discussion of automation on
Window platform

 Server automation consolidates task and process automation into a single solution for
more efficient application deployment as well as ongoing management across virtual and
physical systems.
 It enables end-to-end management through the creation of workflows that automatically
coordinate tasks and processes, leading to a reduction in human-caused errors.
 Server automation can reduce the complexity of manual server management while
simultaneously increasing efficiency and effectiveness (S. Watts, 2020).
Cont’d

 They are many automation tools used on windows platforms such as WinAppDriver,
Winium TestArchitect, Micro Focus UFT (formerly HP QTP), PowerShell etc. but in this
discussion we are going to focus on Powershell.
 Managing scheduled tasks with PowerShell is made possible with the use of
the ScheduledTasks module that’s built-in to Windows.
References

 basic layout and structure of a bash shell script . (n.d.). Retrieved from landoflinux:
[Link]
 Bourne, K. C. (2014). Application Administrators Handbook || UNIX Tools.
 cron command in Linux with Examples . (2021, january 1). Retrieved from GeeksforGeeks:
[Link]
 cron command in Linux with Examples . (2021, january 22). Retrieved from GeeksforGeeks:
[Link]
 Schkn. Cron Jobs and Crontab on Linux explained (2019). https:// devconnected. Com/cron-jobs and
crontab-on-linux-explained/.
 [Link]. understanding crontabs in Linux with Examples (2019), https:// Linux [Link]/ crontab/ #qu.
 Mike F. Robbins, S. W. (2021, June 10). Getting Started with PowerShell. Retrieved from Microsoft:
[Link]
 Nguyen, T. (2o21, June 14). Automation Tools for Desktop Apps. Retrieved from LogiGear:
[Link]
 What’s the Difference Between Bash, Zsh, and Other Linux Shells? (2017, June 20). Retrieved from How-To
Geek: [Link]

You might also like