Nic Shulver, Scripts and Batch files Scripting in Windows and Linux What is scripting? What is it for? DOS/Windows batch files.

Slides:



Advertisements
Similar presentations
Chapter Seven Unix Shell Environments1 System Programming UNIX Shell Environments.
Advertisements

CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Unix Presentation. What is an Operating System An operating system (OS) is a program that allows you to interact with the computer -- all of the software.
What is Unix Prepared by Dr. Bahjat Qazzaz. What is Unix UNIX is a computer operating system. An operating system is the program that – controls all the.
Linux Shell. 2 Linux Command-Line Interface ■ Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact.
Linux Commands LINUX COMMANDS.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Shell Programming, or Scripting Shirley Moore CPS 5401 Fall August 29,
User Interfaces Operating Systems Lecture 2, 20 March 2003 Mr. Greg Vogl Uganda Martyrs University.
TOPIC 5.0 LINUX SHELLS.
Using the Bash Shell. Linux Shell Options Linux provides a range of options for shells. bash –The GNU Bourne Again Shell (bash) bsh – The Bourne Shell.
Welcome to CSE  Name: Di Cao   Classroom: DL357  Class Time: T 8:30am - 9:18am  Office.
Introduction to Linux Operating System Tutorial 1
Overview of Linux CS3530 Spring 2014 Dr. José M. Garrido Department of Computer Science.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Introduction to Shell Script Programming
2008 Bangkok, Thailand Scripting Tools, languages and the Shell intERLab at AIT Network Management Workshop March – Bangkok, Thailand.
Chapter 6: Shell Programming
CENT 305 Information Systems Security Linux Introduction.
July 17, 2003Serguei A. Mokhov, 1 Shells and Shell Scripts COMP 444/5201 Revision 1.3 January 25, 2005.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
LINUX System : Lecture 6 Shell Programming
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
Chapter 2: Linux & POSIX “She sells bash shells by the C shore”
UNIX/LINUX SHELLS.  “A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
1 Applied CyberInfrastructure Concepts ISTA 420/520 Fall Nirav Merchant Bio Computing & iPlant Collaborative Eric Lyons.
UNICOS. When it comes to solving real-world problems, leading-edge hardware is only part of the solution. A complete solution also requires a powerful.
Unix/Linux for beginners:
Unix Shell Environments February 23rd, 2004 Class Meeting 6.
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
CSC414 “Introduction to UNIX/ Linux” Lecture 5. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
Unix – Linux CS3353 Ssystem Administration. OS The Operating System – Acts as the interface to all software, hardware, and users of a computer. – Requires.
UNIX Shell Dr. Tran, Van Hoai
Customizing the Shell Environment. UNIX Shells Two characteristics of shells –Interactive: prompts ($) and waits for your response/requests –Noninteractive:
System Administrator Responsible for? Install OS Network Configuration Security Configuration Patching Backup Performance Management Storage Management.
Executable scripts. So far We have made scripts echo hello #for example And called it hello.sh Run it as sh hello.sh This only works from current directory?
Introduction to Scripting Workshop October
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
System Administrator Responsible for? Install OS Network Configuration Security Configuration Patching Backup Performance Management Storage Management.
Introduction to UNIX CS465. What is UNIX? (1) UNIX is an Operating System (OS). An operating system is a control program that allocates the computer's.
Unix Advanced Shells Chapter 10. Unix Shells u Command Line Interpreter –once logged in, login gives control to a shell –it prompts for input, then parses,
Batch Files Weaker form of UNIX shell scripts Copyright © by Curt Hill.
Lab 8 Overview Apache Web Server. SCRIPTS Linux Tricks.
Linux A practical introduction. 1)Background and Getting Started Linux is an operating system with multiple providers Red Hat/CentOS (our version) Ubuntu.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Configuration your environment Many user-configurable Unix programs (such as your shell) read configuration files when they start up. These configuration.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
Unix Scripting Session 1 March 6, 2008.
CIRC Winter Boot Camp 2017 Baowei Liu
Andy Wang Object Oriented Programming in C++ COP 3330
Agenda Bash Shell Scripting – Part II Logic statements Loop statements
CAP652 Lecture - Shell Programming
Unix Shells.
LINUX System : Lecture 5 (English-Only Lecture)
Guide To UNIX Using Linux Third Edition
By Jonathan Rinfret CREATING A BASH SCRIPT By Jonathan Rinfret
The Linux Operating System
John Carelli, Instructor Kutztown University
Shells, Help, and Paths.
Linux Professor Sabol.
Unix Shell Environments
Linux Commands LINUX COMMANDS.
Bash Scripting CS 580U - Fall 2018.
Presentation transcript:

Nic Shulver, Scripts and Batch files Scripting in Windows and Linux What is scripting? What is it for? DOS/Windows batch files Windows Environment Variables Example batch files UNIX/Linux shell scripting Linux Environment Variables Example shell scripts Conclusion

Nic Shulver, Scripts and Batch files What is scripting? What is it for? Scripting is an extension of the text-based command-line interface Instead of repetitively typing in a sequence of commands, put them in a file, then just “run” the file with a single command The basic concept is a bit like macros in a spreadsheet or word processor Automation of repetitive commands reduces errors A flexible scripting system becomes a “system programming language” A good scripting system allows complex tasks to be automated

Nic Shulver, Scripts and Batch files DOS and Windows Early PC’s had DOS (Disc Operating System), a text-only command-line interface Current systems use GUIs Automation is simpler in text-based systems – so batch scripts are still useful Windows NT (3.5, 2000, XP and so on) have an enhanced command-line interface The examples that follow give a glimpse into the style of command shell batch scripting Many batch files to file or directory manipulation. Often they need contextual information contained in the system’s “environment variables”

Nic Shulver, Scripts and Batch files Some NT Environment Variables ALLUSERSPROFILE=C:\Documents and Settings\All Users APPDATA=C:\Documents and Settings\nas1\Application Data CLASSPATH="C:\WINDOWS\system32\QTJava.zip" CommonProgramFiles=C:\Program Files\Common Files … NUMBER_OF_PROCESSORS=2 OS=Windows_NT PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH PROCESSOR_ARCHITECTURE=x86 PROCESSOR_IDENTIFIER=x86 Family 15 Model 2 Stepping 9, GenuineIntel PROCESSOR_LEVEL=15 PROCESSOR_REVISION=0209 … USERPROFILE=C:\Documents and Settings\nas1 windir=C:\WINDOWS WINVERSION=XP

Nic Shulver, Scripts and Batch files Examples: NT off rem Checks which machine we're running on first... if "%USERNAME%"=="nas1" goto MachineOK echo No! Wrong Machine!!!! goto EndOfScript :MachineOK echo Yes! This is the right machine. :EndOfScript

Nic Shulver, Scripts and Batch files More complex batch off off > allMyXLS.bat echo rem Built by robots! >> allMyXLS.bat for %x IN (*.xls) DO echo print %x >> allMyXLS.bat echo rem All done >> allMyXLS.bat call off rem Built by robots! print attendanceS2_Feb2006.xls print CPU_Speed_Intel.xls print CPU_Speed_Intel_v2.xls print csa marks xls rem All done

Nic Shulver, Scripts and Batch files Useful but off set theDate=%date% set theDate2=%theDate:/=-% md %theDate2% copy *.xls %theDate2% set theDate= set theDate2= This example creates two environment variables, uses one then destroys both The first variable holds the date (e.g. 28/07/2009), the second holds a modified form of the first (e.g ) The second date is used to create a subdirectory Files are copied into the subdirectory This is a simple “daily backup” script

Nic Shulver, Scripts and Batch files UNIX/Linux shell scripting There are a few different command-line systems or “shells” for Linux The Bourne shell (sh), the original UNIX shell. The C-shell (csh), better for interactive users The tc-shell (tcsh), an improved C-shell The Korn shell (ksh), a commercial (and improved) Bourne shell The “Bourne again” shell (bash), a free, improved Bourne shell with csh-like elements - very popular, part of Linux The Z shell (zsh), Bourne-like with many extra features See:

Nic Shulver, Scripts and Batch files Some Linux Environment Variables USERNAME HOSTNAME LOGNAME MAIL EDITOR - Specifies the editor to be used by default for some commands such as edquota. Usually it is set to vi or emacs with a command like "export EDITOR=emacs". TERM - The type of terminal being used. PATH - The path the system looks in to find commands that the user has entered. HOME - The current user's home directory SHELL - The current shell program that is being executed USER - The name of the current user. TMPDIR - Allows programs that use the tempnam(3) function call to use the directory specified by this variable rather than the /tmp directory. SHLVL - Shows how many shells the user has invoked.

Nic Shulver, Scripts and Batch files Example shell scripts #!/bin/Bash echo Type in a message read sTextInput echo `$sTextInput ` is: $sTextInput #exit 0 Type in a message This is a simple bash demonstration $sTextInput is: This is a simple bash demonstration

Nic Shulver, Scripts and Batch files Example shell scripts #!/bin/Bash # be sure the directory /mnt exists if [ ! -d /mnt ] then mkdir /mnt fi for i in /mnt/floppy/*; do if [ -f $i ]; then # if the file is there filename=${i#/mnt/floppy/} echo copying $i to /etc/$filename cp -p $i /etc/$filename Fi done

Nic Shulver, Scripts and Batch files XKCD - Command Line Fu

Nic Shulver, Scripts and Batch files Conclusion Scripting is very useful NT provides many useful tools for automation However, Linux Bash scripting is far more like programming than NT batch scripting In general, Bash is more powerful than the NT shell UNIX is fifteen years more mature than Windows, so you might expect a difference UNIX was a text-only minicomputer OS for a long time, so text- based systems are very well developed Bash scripting, online book: guide/ guide/