Internet Traffic Measurements. Shell Scripts. School of Electrical Engineering AALTO UNIVERSITY

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "Internet Traffic Measurements. Shell Scripts. School of Electrical Engineering AALTO UNIVERSITY"

Transcription

1 Internet Traffic Measurements Shell Scripts School of Electrical Engineering AALTO UNIVERSITY

2 Page 1 Contents What is a shell script?... 2 Useful Linux commands... 2 Useful commands for data manipulation... 2 Useful Linux commands for using with shell scripts... 3 Basic technics in writing shell scripts... 4 Comments... 4 Execution... 4 Results... 4 Echo command... 4 Reading from terminal... 5 Variables... 5 Mathematical operations... 6 Input/output redirections... 7 Logical operations... 7 Relational operations... 7 Boolean operations... 8 Selections... 8 Loops Pausing the script for specific amount of time Note: Shell scripting is extremely powerful, vast and sometime can be very complex!this guide to shell scripting is just an insight view and a simple introduction to creating and customizing your own shell scripts for tasks that you will be given during the Internet Traffic Measurements course.

3 Page 2 What is a shell script? A shell script as the name implies is a script composed of sequences of commands and statements in a single file designed to be executed by the Unix/Linux shell. Shell scripting is one of the most powerful tools for Unix/Linux admins and ordinary users to facilitate and automate complex day to day tasks such as software upgrades, creating backups, executing different applications, data gatherings and in a fully automated manner. Useful Linux commands Following is a list of useful commands when you are working with Linux operating system. Command cat cd chmod cp find grep head ls mkdir more mv rm rmdir tail touch Description displays contents of a file changes directory to directory name specified changing permissions for file or directory copies a file from the source into the destination finds files searchs file contents for a specified pattern display first few lines of a file Lists available files and folders in current directory creates a new directory displays data in paginated form moves (rename) current filename to a new name removes (Delete) a file delete an existing directory provided if it is empty prints last few lines in a file updates access and modification time of a file Useful commands for data manipulation Following is a list of useful commands for manipulating files and directories in Linux. Command sed awk cmp comm cut diff expand join sort split tr uniq wc vi vim Description stream editor for filtering and transforming text pattern scanning and processing language compares the contents of two files compares sorted data cut out selected fields of each line of a file differential file comparator expands tabs to spaces joins files on some common field sort file data split file into smaller files translate characters report repeated lines in a file count words, lines, and characters opens vi text editor opens vim text editor

4 Page 3 Useful Linux commands for using with shell scripts screen If you log out or close the terminal when you are running a command or script, running program or job will be terminated. In order to avoid this termination due to log out you need to use screen command. screen command runs a virtual shell which is persistent if you log out or close the working terminal. Run screen command by simply typing screen in terminal window. It will create a same shell environment as your current one and make you able to run your commands. When you are done with screen shell environment press CTRL + a and then press d to de-attach from the screen and use screen dr to attach to your running screen environment. crontab crontab is an excellent tool in Linux that make administrators and users able to schedule a task, execution of a command or application at specific time. The general format for inserting an entry in crontab file is as follows: Minute Hour Day of month Month of year Day of week your_task Where Field Value Description Minute 0-59 minutes field Hour 0-23 Hour field Day of month 1-31 day of month field Month of year 1-12 month of year Day of week 0-6 day of week ( 0 is Monday) Note: If you need to schedule your task on every minute or hour or just simply put asterisk * sign in that specific field. For example if you need your task be executed run on every day just insert * in day of month field. If you need to schedule your task on portions of time (for example every 5 minutes) simply use */5 in minute field. Examples: * /path/to/your_script/name_of_your_script.sh Is equivalent to scheduling execution of name_of_your_script.sh on 10th June at 08:30 AM ,16 * * * /path/to/your_script/name_of_your_script.sh

5 Page 4 Is equivalent to scheduling execution of name_of_your_script.sh on at 11:00 and 16:00 on every day. */5 * * * * /path/to/your_script/name_of_your_script.sh Is equivalent to scheduling execution of name_of_your_script.sh at every 5 minutes. Use crontab e to insert or edit your entries in your crontab file and crontab l to list your current crontab entries. Basic technics in writing shell scripts Create an empty file using your favorite text editor, make it executable and change its extension to.sh. Comments Every line which begins with # symbol is considered as comment and will not executed by the shell. The only exception to this is where you introduce the interpreter for your script in the first line which might look something like. Use comments as much as possible to make your code more clear. Execution Run your script by using./name_of_your_script.sh if you are in the directory as the script is or use the file absolute path (such as /user/local/my_scripts/name_of_your_script.sh). Results If your script produces any result then the result would be saved in a same place as the script is located, if you have not specified any other location to save those results. Echo command Command echo is used to echo (print) a string value on the terminal echo "Hello world!" Following options and scape characters can be used with echo command: \e allows scape characters in text

6 Page 5 \b backspace \n print new line \r carriage return \t print tab \c suppress trailing new line \a alert \\backslash Reading from terminal Use read statement if you need to read data from the terminal. echo "Please enter a number: " read digit1 echo "please enter another number: " read digit2 echo "First entered digits is: $digit1 and second entered digit is: $digit2" Variables In shell there are 2 different types of variables including user defined variables which can be defined and used by the users, and system defined variables which is created and used by the system (it can be used by the users as well). You simply can define your own variables by declaring and assigning value to them by using following format: variable_name=value Please note that like any other scripting language you need to declare your variables before you invoke them or you will get an error. You can use echo $variable_name to see the value assigned to a specific variable.

7 Page 6 Myvariable1=10 Myvariable2="tree" echo $Myvariable1 10 echo $Myvariable2 tree Or if you need to check the value assigned to one of the system variable: echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin Note: String variables need to be wrapped in double quotes so anything inside a double quotes will be considered as text. Note: Back quote is used to wrap an executable object. echo -e "Printing the Calendar \n `cal`" Where the cal is the shell command needs to be executed. Mathematical operations In order to perform mathematical operation you need to invoke expr using following format: expr operand1 operator operand2 expr Following tables list the available operators in shell: Operator Description Example + addition expr > 14 - subtraction expr > 10 \* multiplication expr 10 \* 4 --> 40 / Division(integer) expr 10 / 4 --> 2 % reminder expr 10 % 4 --> 2

8 Page 7 Input/output redirections By default all commands, applications and scripts display their output to standard output (terminal) but in programing you often might need to redirect output from a program or script to a file or another program or feed a specific information to a program from a output of another file. In these scenarios you need to redirect your input or output using following operators: Operator Description Example >> redirecting and appending the output ls *.conf >> filelist.txt > redirecting and overriding the output ls *.conf > filelist.txt < redirecting the input wc -l < my_script.sh piping the output of command to input of another command cat /etc/passwd grep root Logical operations In all scripting/programing languages you often need to evaluates some expressions or make some decisions based on the result of those evaluations. Shell scripts support logical operations and evaluate the logical expressions to TRUE (1) or FALSE (0) like any other scripting language. Operator Description Example Result > greater than operator 100 > 200 False < less than operator 200 > 100 True == equal operator 100 == 200 False!= Not equal operator 100!= 200 True Relational operations Shell supports following relational operators which are specific to numeric values. These operators would not work for string values unless their value is numeric. a=10 b=15 Operator Description Example Result -eq checks if the value of two operands are equal. [ $a -eq $b ] False -ne checks if the value of two operands are not equal. [ $a -ne $b ] True -gt checks if the value of first operand is greater than the second [ $a -gt $b ] False operand. -lt checks if the value of first operand is less than the second [ $a -lt $b ] True operand. -ge checks if the value of first operand is greater than or equal the [ $a -ge $b ] False second operand. -le checks if the value of first operand is less than or equal the [ $a -le $b ] True second operand. Note: Put your expressions inside the square braces with one space after and before the braces.

9 Page 8 Boolean operations Like any other scripting language shell scripts support Boolean operations as mentioned in following table: Operator Description Example! negation operator [! false ] -o logical OR [ $a -lt 200 -o $b -gt 100 ] -a logical AND [ $a -lt 200 -a $b -gt 100 ] Selections In programing you often need execute some codes if and only if a specific condition evaluates to TRUE or FALSE. Shell scripts supports different types of selections including: if...fi statements if...else...fi statements if...elif...else...fi statements By using an if fi statement in your shell scripts you are able to check for a conditions and if the conditions is set (evaluates to TRUE) then try to execute other line of codes by using following syntax: if [ expression ] then your block of codes to be executed if the expression is set fi echo "Please enter a number: " read digit1 echo "please enter another number: " read digit2 if [ $digit1 -gt $digit2 ] then echo "Digit1 is greater than Digit2" fi

10 Page 9 if fi statements only include required codes to execute only if the conditions is True but sometimes you also need a block of codes to execute if the condition is not set. if...else...fi statements are designed to meet this requirement as follows: if [ expression ] then else your block of codes to be executed if expression is set your block of codes to be executed if expression is not set echo "Please enter a number: " read digit1 echo "please enter another number: " read digit2 if [ $digit1 -gt $digit2 ] then echo "Digit1 is greater than Digit2" else echo "Digit1 is less than Digit2" fi If you need to check for several conditions then you need to invoke if...elif...fi statement by using following format: if [ expression1 ] then your block of codes to be executed if expression1 is set elif [ expression2 ]

11 Page 10 then your block of codes to be executed if expression2 is set elif [ expression3 ] then your block of codes to be executed if expression3 is set else your block of codes to be executed if no expression is true fi Note: if...elif...fi statement might not be suitable for some situations due to efficiency issues so it is better if you consider using case...esac statement by using following format: case word in pattern1) your block of codes to be executed if pattern1 matches ;; pattern2) your block of codes to be executed if pattern2 matches ;; pattern3) esac your block of codes to be executed if pattern3 matches ;; The interpreter checks each case against the value of the expression until a match is found. If nothing matches, a default condition will be used.

12 Page 11 echo "please enter name of an animal: " read animal case "$animal" in "cat") echo "Cat is selected" ;; "dog") echo "Dog is selected" ;; "rabbit") echo "Rabbit is selected" ;; esac Loops Using the loops make the programs able to repetitively execute a block of codes as much as desired. Shell scripts supports different kinds of loops for different situations including: while loop for loop until loop select loop while loops make you able to execute your block of codes until a specific condition is set and stop the execution of that block when the conditions is no longer valid (is not evaluated to True). while loops can be used in shell scripts using following format: while [ condition ] do done your block of codes to be executed if the conditions is set a=0 while [ $a -lt 10 ]

13 Page 12 do echo $a a=`expr $a + 1` done while loops are excellent for situations when you do not have any idea about how many times it is required to execute the code before terminating the loop and making decision for running or terminating the loop is only made by evaluation of condition defined for the loop. On the other hand if you as the programmer know exactly how many times you need to execute your code before terminating the loop then it is better to use for loops with following formats in you code: for loop_variable in condition_set do done your block of codes to be executed or using following format for ((initial_action; loop_continuation_condition; action-after-eachiteration)) do done your block of codes to be executed for var in do echo $var done

14 Page 13 Or equivalently by using other format: for (( var = 0 ; var < 10; var++ )) do echo "$var" done Pausing the script for specific amount of time If you need to execute your script on specific interval (for example every 5 minute) then you can use crontab files or you can use sleep statement and ask your script to pause for specific amount of time and then start execution of rest of the script once again. You can use sleep xy where x is amount of time and y can be: s for seconds (the default) m for minutes h for hours d for days echo "Time is: `date`" sleep 2m echo "Time after sleep command is : `date`"

Tutorial 0A Programming on the command line

Tutorial 0A Programming on the command line Tutorial 0A Programming on the command line Operating systems User Software Program 1 Program 2 Program n Operating System Hardware CPU Memory Disk Screen Keyboard Mouse 2 Operating systems Microsoft Apple

More information

Shell Scripting Crash Course

Shell Scripting Crash Course Shell Scripting Crash Course Travis Phillips JAX LUG Overview What is a shell script What can I do with a shell script How to build shell scripts Syntax basics Basic useful shell commands Pipes and redirectors

More information

UNIX - USEFUL COMMANDS

UNIX - USEFUL COMMANDS UNIX - USEFUL COMMANDS http://www.tutorialspoint.com/unix/unix-useful-commands.htm Copyright tutorialspoint.com This quick guide lists commands, including a syntax and brief description. For more detail,

More information

Unix Scripts and Job Scheduling

Unix Scripts and Job Scheduling Unix Scripts and Job Scheduling Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu/~spring Overview Shell Scripts

More information

HP-UX Essentials and Shell Programming Course Summary

HP-UX Essentials and Shell Programming Course Summary Contact Us: (616) 875-4060 HP-UX Essentials and Shell Programming Course Summary Length: 5 Days Prerequisite: Basic computer skills Recommendation Statement: Student should be able to use a computer monitor,

More information

The Command Line. Matthew Bender. Friday 9 th October, CMSC Command Line Workshop

The Command Line. Matthew Bender. Friday 9 th October, CMSC Command Line Workshop The Command Line Matthew Bender CMSC Command Line Workshop Friday 9 th October, 2015 Matthew Bender (2015) The Command Line Friday 9 th October, 2015 1 / 22 Functions Section 1 Functions Matthew Bender

More information

Command Line - Part 1

Command Line - Part 1 Command Line - Part 1 STAT 133 Gaston Sanchez Department of Statistics, UC Berkeley gastonsanchez.com github.com/gastonstat Course web: gastonsanchez.com/teaching/stat133 GUIs 2 Graphical User Interfaces

More information

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script Shell Programming Shell Scripts (1) Basically, a shell script is a text file with Unix commands in it. Shell scripts usually begin with a #! and a shell name For example: #!/bin/sh If they do not, the

More information

What is Shell Script?

What is Shell Script? Linux Shell Scripts What is Shell Script? We have seen some basic shell commands, it s time to move on to scripts. There are two ways of writing shell programs. You can type a sequence of commands and

More information

Introduction to Shell Programming

Introduction to Shell Programming Introduction to Shell Programming what is shell programming? about cygwin review of basic UNIX TM pipelines of commands about shell scripts some new commands variables parameters and shift command substitution

More information

Linux command line. An introduction to the Linux command line for genomics. Susan Fairley

Linux command line. An introduction to the Linux command line for genomics. Susan Fairley Linux command line An introduction to the Linux command line for genomics Susan Fairley Aims Introduce the command line Provide an awareness of basic functionality Illustrate with some examples Provide

More information

A Crash Course on UNIX

A Crash Course on UNIX A Crash Course on UNIX UNIX is an "operating system". Interface between user and data stored on computer. A Windows-style interface is not required. Many flavors of UNIX (and windows interfaces). Solaris,

More information

Lab Manual. Unix and Linux Programming (Pr) COT-218 and IT-214

Lab Manual. Unix and Linux Programming (Pr) COT-218 and IT-214 Lab Manual Unix and Linux Programming (Pr) COT-218 and IT-214 Lab Instructions Several practicals / programs? Whether an experiment contains one or several practicals /programs One practical / program

More information

Hands-On UNIX Exercise:

Hands-On UNIX Exercise: Hands-On UNIX Exercise: This exercise takes you around some of the features of the shell. Even if you don't need to use them all straight away, it's very useful to be aware of them and to know how to deal

More information

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print In the simplest terms, grep (global regular expression print) will search input

More information

CS2720 Practical Software Development

CS2720 Practical Software Development Page 1 Rex Forsyth CS2720 Practical Software Development CS2720 Practical Software Development Scripting Tutorial Srping 2011 Instructor: Rex Forsyth Office: C-558 E-mail: forsyth@cs.uleth.ca Tel: 329-2496

More information

Bash shell programming Part II Control statements

Bash shell programming Part II Control statements Bash shell programming Part II Control statements Deniz Savas and Michael Griffiths 2005-2011 Corporate Information and Computing Services The University of Sheffield Email M.Griffiths@sheffield.ac.uk

More information

Unix tutorial. Introduction to Unix. VI, March Page 1

Unix tutorial. Introduction to Unix.  VI, March Page 1 Unix tutorial Introduction to Unix http://linux.oreilly.com/ Page 1 Unix tutorial Outline Basic background in Unix structure Directories and files I (listing, navigation, filenames) Directories and files

More information

Lecture 4: Writing shell scripts

Lecture 4: Writing shell scripts Handout 5 06/03/03 1 Your rst shell script Lecture 4: Writing shell scripts Shell scripts are nothing other than les that contain shell commands that are run when you type the le at the command line. That

More information

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2 Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................

More information

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment .i.-' `-. i..' `/ \' _`.,-../ o o \.' ` ( / \ ) \\\ (_.'.'"`.`._) /// \\`._(..: :..)_.'// \`. \.:-:. /.'/ `-i-->..

More information

ICS 351: Today's plan

ICS 351: Today's plan ICS 351: Today's plan routing protocols linux commands Routing protocols: overview maintaining the routing tables is very labor-intensive if done manually so routing tables are maintained automatically:

More information

Unix Sampler. PEOPLE whoami id who

Unix Sampler. PEOPLE whoami id who Unix Sampler PEOPLE whoami id who finger username hostname grep pattern /etc/passwd Learn about yourself. See who is logged on Find out about the person who has an account called username on this host

More information

Fred Hantelmann LINUX. Start-up Guide. A self-contained introduction. With 57 Figures. Springer

Fred Hantelmann LINUX. Start-up Guide. A self-contained introduction. With 57 Figures. Springer Fred Hantelmann LINUX Start-up Guide A self-contained introduction With 57 Figures Springer Contents Contents Introduction 1 1.1 Linux Versus Unix 2 1.2 Kernel Architecture 3 1.3 Guide 5 1.4 Typographical

More information

Syntax: cd <Path> Or cd $<Custom/Standard Top Name>_TOP (In CAPS)

Syntax: cd <Path> Or cd $<Custom/Standard Top Name>_TOP (In CAPS) List of Useful Commands for UNIX SHELL Scripting We all are well aware of Unix Commands but still would like to walk you through some of the commands that we generally come across in our day to day task.

More information

Navigating within the GNU/Linux Filesystem

Navigating within the GNU/Linux Filesystem Navigating within the GNU/Linux Filesystem The purpose of this section is to provide a few basic GNU/Linux commands to aide new users locate areas on the ODU Turing cluster. The commands presented are

More information

Thirty Useful Unix Commands

Thirty Useful Unix Commands Leaflet U5 Thirty Useful Unix Commands Last revised April 1997 This leaflet contains basic information on thirty of the most frequently used Unix Commands. It is intended for Unix beginners who need a

More information

Cisco Networking Academy Program Curriculum Scope & Sequence. Fundamentals of UNIX version 2.0 (July, 2002)

Cisco Networking Academy Program Curriculum Scope & Sequence. Fundamentals of UNIX version 2.0 (July, 2002) Cisco Networking Academy Program Curriculum Scope & Sequence Fundamentals of UNIX version 2.0 (July, 2002) Course Description: Fundamentals of UNIX teaches you how to use the UNIX operating system and

More information

USEFUL UNIX COMMANDS

USEFUL UNIX COMMANDS cancel cat file USEFUL UNIX COMMANDS cancel print requested with lp Display the file cat file1 file2 > files Combine file1 and file2 into files cat file1 >> file2 chgrp [options] newgroup files Append

More information

Tutorial Guide to the IS Unix Service

Tutorial Guide to the IS Unix Service Tutorial Guide to the IS Unix Service The aim of this guide is to help people to start using the facilities available on the Unix and Linux servers managed by Information Services. It refers in particular

More information

Birmingham Environment for Academic Research. Introduction to Linux Quick Reference Guide. Research Computing Team V1.0

Birmingham Environment for Academic Research. Introduction to Linux Quick Reference Guide. Research Computing Team V1.0 Birmingham Environment for Academic Research Introduction to Linux Quick Reference Guide Research Computing Team V1.0 Contents The Basics... 4 Directory / File Permissions... 5 Process Management... 6

More information

CS2043 - Unix Tools & Scripting Lecture 9 Shell Scripting

CS2043 - Unix Tools & Scripting Lecture 9 Shell Scripting CS2043 - Unix Tools & Scripting Lecture 9 Shell Scripting Spring 2015 1 February 9, 2015 1 based on slides by Hussam Abu-Libdeh, Bruno Abrahao and David Slater over the years Announcements Coursework adjustments

More information

Introduction to Shell Scripting

Introduction to Shell Scripting Introduction to Shell Scripting Lecture 1. Shell scripts are small programs. They let you automate multi-step processes, and give you the capability to use decision-making logic and repetitive loops. 2.

More information

Command Line Crash Course For Unix

Command Line Crash Course For Unix Command Line Crash Course For Unix Controlling Your Computer From The Terminal Zed A. Shaw December 2011 Introduction How To Use This Course You cannot learn to do this from videos alone. You can learn

More information

A UNIX/Linux in a nutshell

A UNIX/Linux in a nutshell bergman p.1/23 A UNIX/Linux in a nutshell Introduction Linux/UNIX Tommi Bergman tommi.bergman[at]csc.fi Computational Environment & Application CSC IT center for science Ltd. Espoo, Finland bergman p.2/23

More information

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003 Basic C Shell helpdesk@stat.rice.edu 11th August 2003 This is a very brief guide to how to use cshell to speed up your use of Unix commands. Googling C Shell Tutorial can lead you to more detailed information.

More information

Linux Tutorial 1. Prepared by Mohamed Elmahdy. M.Stonebank. (surrey.ac.uk) under Creative Commons licence.

Linux Tutorial 1. Prepared by Mohamed Elmahdy. M.Stonebank. (surrey.ac.uk) under Creative Commons licence. Linux Tutorial 1 Prepared by Mohamed Elmahdy 1 This Linux tutorial is a modified version of the tutorial A beginners guide to the Unix and Linux operating system by M.Stonebank. (surrey.ac.uk) under Creative

More information

Introduction to the UNIX Operating System and Open Windows Desktop Environment

Introduction to the UNIX Operating System and Open Windows Desktop Environment Introduction to the UNIX Operating System and Open Windows Desktop Environment Welcome to the Unix world! And welcome to the Unity300. As you may have already noticed, there are three Sun Microsystems

More information

Linux System Administration on Red Hat

Linux System Administration on Red Hat Linux System Administration on Red Hat Kenneth Ingham September 29, 2009 1 Course overview This class is for people who are familiar with Linux or Unix systems as a user (i.e., they know file manipulation,

More information

An A-Z Index of the Apple OS X command line (TERMINAL) The tcsh command shell of Darwin (the open source core of OSX)

An A-Z Index of the Apple OS X command line (TERMINAL) The tcsh command shell of Darwin (the open source core of OSX) An A-Z Index of the Apple OS X command line (TERMINAL) The tcsh command shell of Darwin (the open source core of OSX) alias alloc awk Create an alias List used and free memory Find and Replace text within

More information

BASH Scripting. A bash script may consist of nothing but a series of command lines, e.g. The following helloworld.sh script simply does an echo.

BASH Scripting. A bash script may consist of nothing but a series of command lines, e.g. The following helloworld.sh script simply does an echo. BASH Scripting bash is great for simple scripts that automate things you would otherwise by typing on the command line. Your command line skills will carry over to bash scripting and vice versa. bash comments

More information

Systems Programming & Scripting

Systems Programming & Scripting Systems Programming & Scripting Lecture 14 - Shell Scripting: Control Structures, Functions Syst Prog & Scripting - Heriot Watt University 1 Control Structures Shell scripting supports creating more complex

More information

Introduction to Unix. Unix tutorial. Unix tutorial. Outline. Basic background in Unix structure

Introduction to Unix. Unix tutorial. Unix tutorial. Outline.  Basic background in Unix structure Unix tutorial Introduction to Unix http://linux.oreilly.com/ Page 1 Unix tutorial Outline Basic background in Unix structure Directories and files I (listing, navigation, filenames) Directories and files

More information

Open Source Computational Fluid Dynamics

Open Source Computational Fluid Dynamics Open Source Computational Fluid Dynamics An MSc course to gain extended knowledge in Computational Fluid Dynamics (CFD) using open source software. Teachers: Miklós Balogh and Zoltán Hernádi Department

More information

An Introduction to the Linux Command Shell For Beginners

An Introduction to the Linux Command Shell For Beginners An Introduction to the Linux Command Shell For Beginners Presented by: Victor Gedris In Co-Operation With: The Ottawa Canada Linux Users Group and ExitCertified Copyright and Redistribution This manual

More information

LECTURE-7. Introduction to DOS. Introduction to UNIX/LINUX OS. Introduction to Windows. Topics:

LECTURE-7. Introduction to DOS. Introduction to UNIX/LINUX OS. Introduction to Windows. Topics: Topics: LECTURE-7 Introduction to DOS. Introduction to UNIX/LINUX OS. Introduction to Windows. BASIC INTRODUCTION TO DOS OPERATING SYSTEM DISK OPERATING SYSTEM (DOS) In the 1980s or early 1990s, the operating

More information

AN INTRODUCTION TO UNIX

AN INTRODUCTION TO UNIX AN INTRODUCTION TO UNIX Paul Johnson School of Mathematics September 24, 2010 OUTLINE 1 SHELL SCRIPTS Shells 2 COMMAND LINE Command Line Input/Output 3 JOBS Processes Job Control 4 NETWORKING Working From

More information

Introduction to Mac OS X

Introduction to Mac OS X Introduction to Mac OS X The Mac OS X operating system both a graphical user interface and a command line interface. We will see how to use both to our advantage. Using DOCK The dock on Mac OS X is the

More information

The Linux Operating System and Linux-Related Issues

The Linux Operating System and Linux-Related Issues Review Questions: The Linux Operating System and Linux-Related Issues 1. Explain what is meant by the term copyleft. 2. In what ways is the Linux operating system superior to the UNIX operating system

More information

Tutorial on Linux Basics. KARUNYA LINUX CLUB

Tutorial on Linux Basics. KARUNYA LINUX CLUB Tutorial on Linux Basics KARUNYA LINUX CLUB www.karunya.edu/linuxclub Outline 1. Overview of Linux System 2. Basic Commands 3. Relative & Absolute Path 4. Redirect, Append and Pipe 5. Permission 6. Process

More information

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share. LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

More information

Answers to Even-Numbered Exercises

Answers to Even-Numbered Exercises 28 Answers to Even-Numbered Exercises 1. Rewrite the journal script of Chapter 9 (question 5, page 340) by adding commands to verify that the user has write permission for a le named journal-le in the

More information

Shell Scripting. 2014/10/09 Victor Eijkhout

Shell Scripting. 2014/10/09 Victor Eijkhout Shell Scripting 2014/10/09 Victor Eijkhout What is a shell? Command interpreter: listens for your commands, executes, shows output Toolbox: chain together commands with pipes Programming language: Variables

More information

Extreme computing lab exercises Session one

Extreme computing lab exercises Session one Extreme computing lab exercises Session one Michail Basios (m.basios@sms.ed.ac.uk) Stratis Viglas (sviglas@inf.ed.ac.uk) 1 Getting started First you need to access the machine where you will be doing all

More information

Advanced Bash Scripting. Joshua Malone (jmalone@ubergeeks.com)

Advanced Bash Scripting. Joshua Malone (jmalone@ubergeeks.com) Advanced Bash Scripting Joshua Malone (jmalone@ubergeeks.com) Why script in bash? You re probably already using it Great at managing external programs Powerful scripting language Portable and version-stable

More information

Agenda. Using HPC Wales 2

Agenda. Using HPC Wales 2 Using HPC Wales Agenda Infrastructure : An Overview of our Infrastructure Logging in : Command Line Interface and File Transfer Linux Basics : Commands and Text Editors Using Modules : Managing Software

More information

Unix Tutorial. By Joshua Lande SASS. January 21

Unix Tutorial. By Joshua Lande SASS. January 21 Unix Tutorial By Joshua Lande SASS January 21 This is not a philosophy talk! Doug McIlroy, the inventor of Unix pipes and one of the founders of the Unix tradition, summarized the philosophy as follows:

More information

Extreme computing lab exercises Session one

Extreme computing lab exercises Session one Extreme computing lab exercises Session one Miles Osborne (original: Sasa Petrovic) October 23, 2012 1 Getting started First you need to access the machine where you will be doing all the work. Do this

More information

Answers to Even-numbered Exercises

Answers to Even-numbered Exercises 11 Answers to Even-numbered Exercises 1. 2. The special parameter "$@" is referenced twice in the out script (page 442). Explain what would be different if the parameter "$* " were used in its place. If

More information

AD Integration & Home Folders

AD Integration & Home Folders AD Integration & Home Folders David Acland Technical Director at Amsys @davidacland ACSE Training Projects & Support What the heck s AD? Uh-oh AD mastered! What I ll be talking about AD Integration Troubleshooting

More information

Lecture 10: More Bash Scripting

Lecture 10: More Bash Scripting Lecture 10: More Bash Scripting CS2042 - UNIX Tools October 22, 2008 Lecture Outline 1 2 3 Basic Operators While shell scripts are usually used to automate more complex tasks, occasionally a little arithmetic

More information

Lecture 4. Regular Expressions grep and sed intro

Lecture 4. Regular Expressions grep and sed intro Lecture 4 Regular Expressions grep and sed intro Previously Basic UNIX Commands Files: rm, cp, mv, ls, ln Processes: ps, kill Unix Filters cat, head, tail, tee, wc cut, paste find sort, uniq comm, diff,

More information

This presentation explains how to monitor memory consumption of DataStage processes during run time.

This presentation explains how to monitor memory consumption of DataStage processes during run time. This presentation explains how to monitor memory consumption of DataStage processes during run time. Page 1 of 9 The objectives of this presentation are to explain why and when it is useful to monitor

More information

Linux System Administration

Linux System Administration Shell Scripts Objective As system administrators it is often necessary to write or modify a script to automate administrator duties We should have a basic understating of the syntax of some basic script

More information

CS 103 Lab Linux and Virtual Machines

CS 103 Lab Linux and Virtual Machines 1 Introduction In this lab you will login to your Linux VM and write your first C/C++ program, compile it, and then execute it. 2 What you will learn In this lab you will learn the basic commands and navigation

More information

KORN SHELL PROGRAMMING CHEAT SHEET

KORN SHELL PROGRAMMING CHEAT SHEET KORN SHELL PROGRAMMING CHEAT SHEET Special Characters Metacharacters have special meaning to the shell unless quoted (by preceding it with a \ or enclosing it in ` `) Inside double quotes parameter and

More information

CSIL MiniCourses. Introduction To Unix (I) John Lekberg Sean Hogan Cannon Matthews Graham Smith. Updated on: 2015-10-14

CSIL MiniCourses. Introduction To Unix (I) John Lekberg Sean Hogan Cannon Matthews Graham Smith. Updated on: 2015-10-14 CSIL MiniCourses Introduction To Unix (I) John Lekberg Sean Hogan Cannon Matthews Graham Smith Updated on: 2015-10-14 What s a Unix? 2 Now what? 2 Your Home Directory and Other Things 2 Making a New Directory

More information

Basic Linux & Package Management. Original slides from GTFO Security

Basic Linux & Package Management. Original slides from GTFO Security Basic Linux & Package Management Original slides from GTFO Security outline Linux What it is? Commands Filesystem / Shell Package Management Services run on Linux mail dns web central authentication router

More information

Command-Line Operations : The Shell. Don't fear the command line...

Command-Line Operations : The Shell. Don't fear the command line... Command-Line Operations : The Shell Don't fear the command line... Shell Graphical User Interface (GUI) Graphical User Interface : displays to interact with the computer - Open and manipulate files and

More information

Exercise 1: Python Language Basics

Exercise 1: Python Language Basics Exercise 1: Python Language Basics In this exercise we will cover the basic principles of the Python language. All languages have a standard set of functionality including the ability to comment code,

More information

Bulk Downloader. Call Recording: Bulk Downloader

Bulk Downloader. Call Recording: Bulk Downloader Call Recording: Bulk Downloader Contents Introduction... 3 Getting Started... 3 Configuration... 4 Create New Job... 6 Running Jobs... 7 Job Log... 7 Scheduled Jobs... 8 Recent Runs... 9 Storage Device

More information

Linux BASH Shell Scripting

Linux BASH Shell Scripting The information presented here should act as a guide to creating quality scripts using the Linux built in BASH scripting language. BASH (Bourne Again Shell) is a scripting language as well as the default

More information

Introduction to Git. Markus Kötter koetter@rrzn.uni-hannover.de. Notes. Leinelab Workshop July 28, 2015

Introduction to Git. Markus Kötter koetter@rrzn.uni-hannover.de. Notes. Leinelab Workshop July 28, 2015 Introduction to Git Markus Kötter koetter@rrzn.uni-hannover.de Leinelab Workshop July 28, 2015 Motivation - Why use version control? Versions in file names: does this look familiar? $ ls file file.2 file.

More information

NLP Programming Tutorial 0 - Programming Basics

NLP Programming Tutorial 0 - Programming Basics NLP Programming Tutorial 0 - Programming Basics Graham Neubig Nara Institute of Science and Technology (NAIST) 1 About this Tutorial 14 parts, starting from easier topics Each time: During the tutorial:

More information

Lecture 22 The Shell and Shell Scripting

Lecture 22 The Shell and Shell Scripting Lecture 22 The Shell and Shell Scripting In this lecture The UNIX shell Simple Shell Scripts Shell variables File System s, IO s, IO redirection Command Line Arguments Evaluating Expr in Shell Predicates,

More information

1 Basic commands. 2 Terminology. CS61B, Fall 2009 Simple UNIX Commands P. N. Hilfinger

1 Basic commands. 2 Terminology. CS61B, Fall 2009 Simple UNIX Commands P. N. Hilfinger CS61B, Fall 2009 Simple UNIX Commands P. N. Hilfinger 1 Basic commands This section describes a list of commonly used commands that are available on the EECS UNIX systems. Most commands are executed by

More information

Higher National Unit Specification. General information for centres. Multi User Operating Systems. Unit code: DH3A 34

Higher National Unit Specification. General information for centres. Multi User Operating Systems. Unit code: DH3A 34 Higher National Unit Specification General information for centres Unit code: DH3A 34 Unit purpose: This Unit is designed to provide candidates with a practical introduction to, and understanding of, the

More information

Unix the Bare Minimum

Unix the Bare Minimum Unix the Bare Minimum Norman Matloff September 27, 2005 c 2001-2005, N.S. Matloff Contents 1 Purpose 2 2 Shells 2 3 Files and Directories 4 3.1 Creating Directories.......................................

More information

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl First CGI Script and Perl Perl in a nutshell Prof. Rasley shebang line tells the operating system where the Perl interpreter is located necessary on UNIX comment line ignored by the Perl interpreter End

More information

UNIX Intro and Basic C shell Scripting

UNIX Intro and Basic C shell Scripting UNIX Intro and Basic C shell Scripting Khaldoun Makhoul khaldoun@nmr.mgh.harvard.edu December 2nd 2010 1 This talk introduces the audience to the basic use of the UNIX/Linux command line tools and to basic

More information

PHP Debugging. Draft: March 19, 2013 2013 Christopher Vickery

PHP Debugging. Draft: March 19, 2013 2013 Christopher Vickery PHP Debugging Draft: March 19, 2013 2013 Christopher Vickery Introduction Debugging is the art of locating errors in your code. There are three types of errors to deal with: 1. Syntax errors: When code

More information

An Introduction to Using the Command Line Interface (CLI) to Work with Files and Directories

An Introduction to Using the Command Line Interface (CLI) to Work with Files and Directories An Introduction to Using the Command Line Interface (CLI) to Work with Files and Directories Mac OS by bertram lyons senior consultant avpreserve AVPreserve Media Archiving & Data Management Consultants

More information

Exercise 4 Learning Python language fundamentals

Exercise 4 Learning Python language fundamentals Exercise 4 Learning Python language fundamentals Work with numbers Python can be used as a powerful calculator. Practicing math calculations in Python will help you not only perform these tasks, but also

More information

INASP: Effective Network Management Workshops

INASP: Effective Network Management Workshops INASP: Effective Network Management Workshops Linux Familiarization and Commands (Exercises) Based on the materials developed by NSRC for AfNOG 2013, and reused with thanks. Adapted for the INASP Network

More information

LINUX SHELL SCRIPTING

LINUX SHELL SCRIPTING LINUX SHELL SCRIPTING @Copyright 2015 1 1. Chapter 1: Quick Introduction to Linux What Is Linux? Who created Linux? Where can I download Linux? How do I Install Linux? Linux usage in everyday life What

More information

ULTEO OPEN VIRTUAL DESKTOP V4.0

ULTEO OPEN VIRTUAL DESKTOP V4.0 ULTEO OPEN VIRTUAL DESKTOP V4.0 MIGRATION GUIDE 28 February 2014 Contents Section 1 Introduction... 4 Section 2 Overview... 5 Section 3 Preparation... 6 3.1 Enter Maintenance Mode... 6 3.2 Backup The OVD

More information

Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick Reference Guide

Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick Reference Guide Open Crystal Reports From the Windows Start menu choose Programs and then Crystal Reports. Creating a Blank Report Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick

More information

QUICK START BASIC LINUX AND G++ COMMANDS. Prepared By: Pn. Azura Bt Ishak

QUICK START BASIC LINUX AND G++ COMMANDS. Prepared By: Pn. Azura Bt Ishak QUICK START BASIC LINUX AND G++ COMMANDS Prepared By: Pn. Azura Bt Ishak FTSM UKM BANGI 2009 Content 1.0 About UBUNTU 1 2.0 Terminal 1 3.0 Basic Linux Commands 3 4.0 G++ Commands 23 1.0 ABOUT UBUNTU Ubuntu

More information

Bitrix Site Manager 4.0. Quick Start Guide to Newsletters and Subscriptions

Bitrix Site Manager 4.0. Quick Start Guide to Newsletters and Subscriptions Bitrix Site Manager 4.0 Quick Start Guide to Newsletters and Subscriptions Contents PREFACE...3 CONFIGURING THE MODULE...4 SETTING UP FOR MANUAL SENDING E-MAIL MESSAGES...6 Creating a newsletter...6 Providing

More information

Using Logon Agent for Transparent User Identification

Using Logon Agent for Transparent User Identification Using Logon Agent for Transparent User Identification Websense Logon Agent (also called Authentication Server) identifies users in real time, as they log on to domains. Logon Agent works with the Websense

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Frequently Used UNIX Commands

Frequently Used UNIX Commands Frequently Used UNIX Commands Command ls Function Lists directory contents. ls -a List directory contents including hidden files. ls -l List directory contents using a long listing format that indicates

More information

SFTP SHELL SCRIPT USER GUIDE

SFTP SHELL SCRIPT USER GUIDE SFTP SHELL SCRIPT USER GUIDE FCA US INFORMATION & COMMUNICATION TECHNOLOGY MANAGEMENT Overview The EBMX SFTP shell scripts provide a parameter driven workflow to place les on the EBMX servers and queue

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

Automating admin tasks using shell scripts and cron Vijay Kumar Adhikari. vijay@kcm

Automating admin tasks using shell scripts and cron Vijay Kumar Adhikari. vijay@kcm Automating admin tasks using shell scripts and cron Vijay Kumar Adhikari vijay@kcm kcm.edu.np How do we go? Introduction to shell scripts Example scripts Introduce concepts at we encounter them in examples

More information

PA2: Word Cloud (100 Points)

PA2: Word Cloud (100 Points) PA2: Word Cloud (100 Points) Due: 11:59pm, Thursday, April 16th Overview You will create a program to read in a text file and output the most frequent and unique words by using an ArrayList. Setup In all

More information

Linux System Administration. System Administration Tasks

Linux System Administration. System Administration Tasks System Administration Tasks User and Management useradd - Adds a new user account userdel - Deletes an existing account usermod - Modifies an existing account /etc/passwd contains user name, user ID #,

More information

SCR. Scripting. Goals of this lab: Prerequisites: LXB

SCR. Scripting. Goals of this lab: Prerequisites: LXB SCR Scripting Goals of this lab: To learn the basics of writing shell scripts. To gain insight in the gains with automating administrative work. To gain practical experience of automating administrative

More information

CHAPTER 5 THE KORN SHELL

CHAPTER 5 THE KORN SHELL CHAPTER 5 THE KORN SHELL ALIASES The Korn shell allows you to create and customize your ow ommands by using the alias command. alias [word [=string]] alias dir= ls F # option-f appends / for files, * for

More information

List of FTP commands for the Microsoft command-line FTP client

List of FTP commands for the Microsoft command-line FTP client You are on the nsftools.com site This is a list of the commands available when using the Microsoft Windows command-line FTP client (requires TCP/IP to be installed). All information is from the Windows

More information