Review Please turn in your homework and practicals Packages, installation, rpm command Apache – Quick and easy way to set up a web server to play around.

Slides:



Advertisements
Similar presentations
Making a “P and J” sandwich
Advertisements

PHYS 2020 Pseudocode. Real Programmers Program in Pencil!  You can save a lot of time if you approach programming in a methodical way.  1) Write a clear.
Substitute FAQs SubFinder Overview. FAQs Do I have to have touch-tone service to use SubFinder? No, but you do need a telephone that can be switched from.
More about Shells1-1 More about Shell  Shells (sh, csh, ksh) are m Command interpreters Process the commands you enter m High-level programming languages.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
Introduction to UNIX A User’s Perspective: Day 2 – Command Basics.
Introduction to Unix – CS 21 Lecture 14. Lecture Overview Lab Questions Backup schemes Using tar to archive Printing in Unix lpr lpq Lprm Quiz 2.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
A crash course in njit’s Afs
CTEC 1863 – Operating Systems Shell Scripting. CTEC F2 Overview How shell works Command line parameters –Shift command Variables –Including.
Shell Programming, or Scripting Shirley Moore CPS 5401 Fall August 29,
Introduction to UNIX/Linux Exercises Dan Stanzione.
Introducing Java.
Welcome to CS 115! Introduction to Programming. Class URL Please write this down!
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”
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface (or Terminal) What is the filesystem tree.
Introduction to Shell Script Programming
CS 7: Introduction to Computer Programming Algorithms.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 9, 2015)
An Introduction to Unix Shell Scripting
Linux Operations and Administration
Computer Programming for Biologists Oct 30 th – Dec 11 th, 2014 Karsten Hokamp  Fill out.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Review Please turn in your homework and practicals sed.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
GNU Compiler Collection (GCC) and GNU C compiler (gcc) tools used to compile programs in Linux.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
CS 390 Unix Programming Summer Unix Programming - CS 3902 Course Details Online Information Please check.
Running the Operational Codes for the Brahmaputra Tom Hopson.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux Operations and Administration
Beyond sh Not everyone is as fond of UNIX as most other people. The tutorial talks about the dark side of UNIX.
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
Quiz 15 minutes Open note, open book, open computer Finding the answer – working to get it – is what helps you learn I don’t care how you find the answer,
Ant & Jar Ant – Java-based build tool Jar – pkzip archive, that contains metadata (a manifest file) that the JRE understands.
Review Please hand in your practicals and homework Regular Expressions with grep.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Introduction.
Guide to Linux Installation and Administration, 2e1 Chapter 11 Using Advanced Administration Techniques.
What is a port The Ports Collection is essentially a set of Makefiles, patches, and description files placed in /usr/ports. The port includes instructions.
Writing Scripts Hadi Otrok COEN 346.
40 Years and Still Rocking the Terminal!
Beginning Fortran Fortran (77) Advanced 29 October 2009 *Black text on white background provided for easy printing.
Review Please hand in any homework and practicals Vim Scripting Inter-device communication.
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?
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Running the Operational Codes for the Brahmaputra Tom Hopson.
How to Improve Your Grades Are your grades rather low? Maybe it's the beginning of school, and your not getting off to a good start. Well, this easy to.
CSCI 330 UNIX and Network Programming Unit X: Shell Scripts II.
Intro to Turtle Graphics (Part 2)
Agenda The Bourne Shell – Part I Redirection ( >, >>,
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
UNIX-21 WEEK 2 4/5/2005. UNIX-22 TOPICS Functions (contd.) pushd, popd, dirs Debugging Shell scripts Scheduling Unix jobs Job Management.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Using Linux Kaya Oğuz Room: 310.
GRID COMPUTING.
Development Environment
Department of Computer Engineering
Chapter 11 Command-Line Master Class
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
Principles of Programming I (CIE 105)
System Administration
CSE 303 Concepts and Tools for Software Development
What is Bash Shell Scripting?
LING 408/508: Computational Techniques for Linguists
Map Reduce Workshop Monday November 12th, 2012
CSE 303 Concepts and Tools for Software Development
Lab 4: Introduction to Scripting
Presentation transcript:

Review Please turn in your homework and practicals Packages, installation, rpm command Apache – Quick and easy way to set up a web server to play around with

Today Scripting

Method of automating repeatable tasks Anything you do more than 3 times, you should script Script = quick program using commands instead of programming language – Ish, there are shell-script specific things you can use, they’re beyond the scope of this class

Programming Breaking down a larger task into smaller instructions that a computer can understand and carry out Making a peanut butter sandwich – Peanut butter, jelly, 2 slices of bread – Spread jelly on one slice, pb on other, combine You don’t say “walk to cupboard, open cupboard, get out peanut butter, put pb on counter, get out bread, close cupboard, etc…”

Computers Are Dumb But computers need all that – they’re not people They can’t interpret those logical steps that we take for granted So we have to break tasks down into those steps a computer understands

Shell Scripts Shell scripts are collections of commands Java/C++ are “compiled” – This allows you to create an object and interact with it in other ways Shell scripts are “interpreted” This means the file starts at the top, it takes the first one It runs the first one, waits for it to finish, and then goes to the next one

Backup Script One of the most useful scripts I have re- created almost every time I start in a new environment is Backup my system So we start with that over-arching task, and break it down Backup what? We don’t need system files, we need user files and application files (maybe temp)

Breaking A Task Down Backup /home Backup /opt Backup /tmp What do we do with it when it’s backed up? Move to another system (let’s say :/opt/backups) Let’s add output to help us see start/finish times

Build a script that… Announces it’s starting and the time Backs up /home, /opt, and /tmp Move to another system (let’s say :/opt/backups) Cleans up after itself Announces it’s finished

Map Commands to Actions Announces it’s starting and the time – echo “Announce and time” and date Backs up /home, /opt, and /tmp – tar file.tar /directory1 /directory2 /directory3 /dir4 etc… Move to another system (let’s say :/opt/backups) – scp from_system to_system Cleans up after itself - ? – rm file Announces it’s finished – echo “done”

Map Commands to Actions echo “Started backing up system at:” date tar backup.tar /home /opt /tmp scp backup.tar :/opt/backups rm backup.tar echo “Finished at:” date

Missing Anything? echo “Started backing up system at:” date tar backup.tar /home /opt /tmp scp backup.tar :/opt/backups rm backup.tar echo “Finished at:” date

New Functionality The ` is called a ‘tic’ Notice ` is not ‘ (tic is not apostrophe) It’s the same key as ~ This runs the command inside a script It inserts the results into your script tar -cvf `hostname`.tar /home /opt /tmp hostname is a command – returns system name This runs hostname and then inserts it into tar

Portability tar -cvf `hostname`.tar /home /opt /tmp This is now ‘portable’ and will work across systems So our system is it136centos65vm Another could be prodWEBcentos65 We can still run this on both systems, and differentiate between the output of the two (by filename) Would create it136centos65vm.tar and would create prodWEBcentos65.tar One script, multiple systems

With a Variable #!/bin/bash $DATE=`date` echo “Started backing up system at $DATE” tar `hostname`.tar /home /opt /tmp scp `hostname`.tar :/opt/backups rm `hostname`.tar echo “Finished at $DATE”

For Experienced Users If you can write a Bash script within 48 hours that: Has your name and today’s date as a comment Prints your username to STDOUT Checks if username is in sudoers file Starts a sleep(1000) command in the background Checks if Apache is installed via RPM Attempts to start Apache Runs regex against the Apache config file that checks for the ‘default’ documentroot Redirects the output to a file in /tmp Kill the sleep(1000) command using job # Come talk to me, this class is going to bore you

Continued Advanced Scripting – Control functions – If-then – Do-while – Variables – User input

Scripting You’ll know it when you see it – “I’m so sick of doing all this for each user!” Break tasks down until each one maps to a single command Each line of a script is a single task (command) Performs a useful, repeatable function – Burnin – “automation”

“Case Study” (Example) I took over the IDS systems It took me six months to make the devices more stable – In between dealing with failures After that, I was dealing with a HIPAA audit where I had to install over 1,000 IDS “agents” I scripted this, and the reporting Every time I was able to install, I’d run my script agents installed within minutes I’d run my reporting script to make sure they were all running I’d Netflix the rest of the day

Quiz Monday 10 Questions – Covering all topics since the last quiz – Open book, open note, open computer Last subject – Will spend a week and a half on ‘regular expressions’ and their utilities And then the final!