+ All Categories
Home > Documents > CIS 90 - Lesson 14

CIS 90 - Lesson 14

Date post: 01-Feb-2016
Category:
Upload: jason
View: 56 times
Download: 0 times
Share this document with a friend
Description:
CIS 90 - Lesson 14. Lesson Module Status Slides – Properties - Flash cards – No-stress quiz – Web calendar summary – Web book pages – Commands – Lab – done Supplies () - Class PC's – Scripts () –. CIS 90 - Lesson 14. Quiz. No Quiz Today !. CIS 90 - Lesson 14. - PowerPoint PPT Presentation
Popular Tags:
71
CIS 90 - Lesson 14 Lesson Module Status • Slides – • Properties - • Flash cards – • No-stress quiz – • Web calendar summary – • Web book pages – • Commands – • Lab – done • Supplies () - • Class PC's – • Scripts () –
Transcript
Page 1: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Lesson Module Status• Slides – • Properties -• Flash cards – • No-stress quiz – • Web calendar summary – • Web book pages – • Commands – • Lab – done• Supplies () -• Class PC's – • Scripts () –

Page 2: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Quiz

Page 3: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Objectives Agenda

• Use conditionals in scripts• Transfer files between computers• Archive directories using tar

• No Quiz - warmup exercise instead

• Questions from last week

• scp

• More scripting

• Tarballs

• Wrap up

= hands on exercise for topic

The UNIX/Linux File System

Page 4: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Previous material and assignment

1. Questions?

2. No labs due today

3. Check grades page

4. Check your class/labs/ directory on Opus for graded work

Page 5: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Warmup ExerciseFind the hidden treasure trove

• Find the treasure buried in you Hidden folder.

• When you find it make sure only you can read it and

nobody can modify it.

Page 6: CIS 90 - Lesson 14

CIS 90 - Lesson 14

scp

Page 7: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Classroom PC's, VMs and Remote Server

One Windows laptop per student

One RH9 Linux VM per laptop

Internet

One RHEL5 serverper class

SSH is a network protocol that enables secure connections between computers

Opus

Page 8: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Telnet and SSH (Secure Shell)

Telnet - all clear text SSH - encrypted

usernamepasswordcat secret

exit

Opus

Local computer

Sniffer view of a Telnet session Sniffer view of a SSH session

Page 9: CIS 90 - Lesson 14

ssh protocol

CIS 90 - Lesson 14

/

Secure Shell Protocol

•Allows secure (encrypted connections between computers)• ssh command – secure login and terminal sessions• scp command – secure file copies between computers

Page 10: CIS 90 - Lesson 14

scp

CIS 90 - Lesson 14

/

Copy commands copy file(s) to a Destination

•cp ‒ copies files on the same computer‒ examples:

cp myscript myscript.v1cp myscript.v1 backups/cp /home/cis90/simmsben/bin/myscript benscript

•scp ‒ copies files between computers:‒ examples:

scp [email protected]:myscript .scp lab45 [email protected]:lab45scp lab45 [email protected]:

Page 11: CIS 90 - Lesson 14

scp

CIS 90 - Lesson 14

scp [email protected]:bin/myscript .

scp lab45 [email protected]:lab45

scp lab45 [email protected]:

command 1st argument 2nd argument (from) (to)

Page 12: CIS 90 - Lesson 14

scp

CIS 90 - Lesson 14

scp [email protected]:bin/myscript .

Remote Local

Copy the file myscript from roddyduk's home bin/ directory on the remote system Opus to "here"

Page 13: CIS 90 - Lesson 14

scp

CIS 90 - Lesson 14

scp [email protected]:bin/myscript .

Remote Local

The username on the remote computer. Needed to login and this defines the home directory for the relative path to the file

Either the IP address or hostname of the remote computer. Need to connect to system on the Internet

Path to file. Relative to user's home directory.

Page 14: CIS 90 - Lesson 14

scp

CIS 90 - Lesson 14

/

Local Linux System

Opus

Logged in to two different systems

Page 15: CIS 90 - Lesson 14

scp

CIS 90 - Lesson 14

/

Local Linux System

Opus

Performing scp copy from Opus to local Red hat system

Page 16: CIS 90 - Lesson 14

scp

CIS 90 - Lesson 14

/

Local Linux System

Opus

Catting files on both systems to verify the copy

Page 17: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Class Exercisescp

• Start up the local VM on the laptops and login as cisco

• Use Putty and login to your account on Opus

• Copy the files banner and myscript from your bin directory on Opus

scp [email protected]:bin/myscript .

scp [email protected]:bin/banner .

• Create a bin directory on your local VM (if needed)

mkdir bin

• Move banner and myscript to your local VM bin directory

mv banner myscript bin/

• Check path and permissions to make insure /home/cisco/bin is in your path and

that myscript and banner have execute permission set.

echo $PATH

ls –l /home/cisco/bin/

• Run the script you made on Opus on your local VM

myscript

Page 18: CIS 90 - Lesson 14

CIS 90 - Lesson 14

To copy multiple files, use the * expansion character

Note, this will copy files, but not directories

Page 19: CIS 90 - Lesson 14

CIS 90 - Lesson 14

To recursively copy files and directories use the –r option

Now all files and directories will be copied

Page 20: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Class Exercisescp

• Copy all the files and directories in your Opus bin directory to your local bin

directory

scp –r [email protected]:bin/* /home/cisco/bin/

• Now see if you can copy your entire poems directory on Opus to a new poems

directory in your local cisco home directory. When finished write the commands

you used on the whiteboard.

Page 21: CIS 90 - Lesson 14

CIS 90 - Lesson 14

scripting

Page 22: CIS 90 - Lesson 14

CIS 90 - Lesson 14

myscript

Page 23: CIS 90 - Lesson 14

CIS 90 - Lesson 14

myscript

Page 24: CIS 90 - Lesson 14

CIS 90 - Lesson 14

myscript

Page 25: CIS 90 - Lesson 14

CIS 90 - Lesson 14

myscript

Page 26: CIS 90 - Lesson 14

CIS 90 - Lesson 14

myscript

Page 27: CIS 90 - Lesson 14

CIS 90 - Lesson 14

myscript

Duke's CIS 90 Final Project 1) Color 2) My Find Command 3) More practice 4) Duke's friend made this one - Thank You 5) Task 5 6) Exit

Enter Your Choice: 3Hello Duke Roddy Wed Dec 3 14:07:07 PST 2008Hit the Enter key to return to menu

Page 28: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Class ExerciseScripting

•Make a short script that does the following:

•Get and displays the user's name

•Runs one command

Page 29: CIS 90 - Lesson 14

CIS 90 - Lesson 14

myscript

Page 30: CIS 90 - Lesson 14

CIS 90 - Lesson 14

myscript

Page 31: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Class ExerciseScripting

•Modify your script to do the following:

•Ask the user a question

•Use a conditional (if statement) that users the

users response.

Page 32: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar

Page 33: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar command

tar file(s)ctvfx

createtable of contents (view)

extract

Note: The full path to each file is stored in the archive and these paths are used when restoring files

tarfilearchive file

files tobackup

options(no – needed)

v = verbose, double v (vv) provides more information

Page 34: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandSingle file example

Backup a web page file

Oops! – file gets deleted

View backed up file

Restore the file

Page 35: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandSingle file example

create

verbose tarfileto use

file to back up(requires full path)

view (table of contents)

verbose tarfileto use

extract

verbose tarfileto use

file in archive to restore(requires full path)

Page 36: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandPay attention to the path stored in the tarfile

Creating the tarfile from another directory using absolute path

[root@benji ~]# tar cvf sample2.tar /opt/lampp/htdocs/sample.htmltar: Removing leading `/' from member names/opt/lampp/htdocs/sample.html[root@benji ~]# tar tvf sample2.tar-rw-r--r-- root/root 194 2008-10-24 10:13:10 opt/lampp/htdocs/sample.html[root@benji ~]#

[root@benji ~]# tar cvf sample2.tar ../opt/lampp/htdocs/sample.htmltar: Removing leading `../' from member names../opt/lampp/htdocs/sample.html[root@benji ~]# tar tvf sample2.tar-rw-r--r-- root/root 194 2008-10-24 10:13:10 opt/lampp/htdocs/sample.html[root@benji ~]#

Note, the leading / gets stripped

This path is used when restoring files

Creating the tarfile from another directory using relative path path

Note, the leading ../ gets stripped

This path is used when restoring files

Page 37: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar command-C option

The –C option can be used to set the starting directory for file to be restored to. Add a – to the other options as well

Page 38: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar command-C option

Change to the directory where the backup was made

Or use the –C option to restore from another directory

Find file to restore in archive

Page 39: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Class Exercisetar command

1. Change to the /opt/lampp/htdocs directory.

2. Backup sample.html using: tar cvf /root/sample.tar sample.html

3. Verify your tarfile contains sample.htmlWhat is the path to sample.html in the tarfile? [Table 1-4]

4. Delete then practice restoring sample.html: To its original location

Where did you have to be to do this? [Table 9-12] To the /tmp directory

Where did you have to be to do this? [Table 17-20]

5. Now use the tar man page to check out the –C directory option. Delete the sample.html in the /tmp directory Restore sample.html from /root to the /tmp directory with

the –C option. What command did you use [Table 5-9]?

Page 40: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandDirectory example

Backup up files (including hidden and sub-directories) starting from "here"

Delete some files

Verify they were backed up

Restore the files that were deleted

Note how tar saves full path for each file backed up

Page 41: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandDirectory example

./xampp/contrib/xmlrss.php

./xampp/contrib/mingstats.html

./xampp/contrib/sql2xml.php

./xampp/contrib/sqlite.pl

./xampp/contrib/BabelSans-B.fdb

./xampp/contrib/oracle.pl

./xampp/contrib/interbase.php

./xampp/contrib/postgresql.php

./xampp/manuals.php

./xampp/cgi.cgi

./xampp/cds.php

./xampp/webalizer.php

./xampp/biorhythm.php

./xampp/AnkeCalligraph.TTF

./xampp/head.php

./xampp/guestbook-zh.pl

./xampp/start.php

./xampp/AnkeCalligraph.fdb

./xampp/mingswf.php

./xampp/mysql.php

./xampp/guestbook-nl.pl

./xampp/navi.php

./xampp/lang.php

./xampp/security.php

./xampp/lang/

./xampp/lang/de.php

./xampp/lang/it.php

./xampp/lang/fr.php

./xampp/lang/es.php

./xampp/lang/pt_br.php

./xampp/lang/nl.php

./xampp/lang/zh.php

./xampp/lang/no.php

./xampp/lang/pl.php

./xampp/lang/languages.php

./xampp/lang/jp.php

./xampp/splash-logo.php

./xampp/langsettings.php

./xampp/.version

./xampp/status.php

./xampp/phonebook.php

./xampp/img/

./xampp/img/rb.gif

./xampp/img/status3.gif

./xampp/img/logo-small.gif

./xampp/img/logo-small.jpg

./xampp/img/new.png

./xampp/img/signature-kay.gif

./xampp/img/lt.gif

./xampp/img/benji-500x420.jpg

./xampp/img/status4.gif

./xampp/img/rt.gif

./xampp/img/strichel.gif

./xampp/img/head-linux.gif

./xampp/img/head-xampp.gif

./xampp/img/xampp-logo.jpg

./xampp/img/head-fuer.gif

./xampp/img/head-for.gif

./xampp/img/head-solaris.gif

./xampp/img/status2.gif

./xampp/img/status1.gif

./xampp/img/head-windows.gif

./xampp/img/logo-big.gif

./xampp/img/signature-oswald.gif

./xampp/img/status5.gif

./xampp/img/blank.gif

./xampp/img/lb.gif

./xampp/img/xampp-logo-new.gif

./xampp/guestbook-es.pl

./xampp/guestbook-de.pl

./xampp/phpinfo.php

./xampp/splash.php

./xampp/guestbook-pt_br.pl

./xampp/guestbook.dat

./xampp/charset.php

./xampp/test.php

./xampp/softwarelist.inc

./xampp/guestbook-it.pl

./xampp/cds-fpdf.php

./xampp/ssi.inc

./xampp/php.php

./xampp/sqlite/

./xampp/sqlite/cdcol

./xampp/sqlite/phonebook.sqlite

./xampp/sqlite/.htaccess

./xampp/xampp.css

./xampp/ming.php

./xampp/showcode.php

./xampp/guestbook-fr.pl

./xampp/guestbook-en.pl

./xampp/iart.php

./.hidden

./favicon.ico

./index.html

createverbose

tarfileto use

files to back up(starting point)

Page 42: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandDirectory example

view(table of contents)

Files to find in archivetarfileverbose

extractFiles to find to extracttarfile

verbose

Page 43: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Class Exercisetar command

1. Change to the /opt/lampp/ directory. Note the htdocs and backup directories.

2. Backup the htdocs directory (including sub-directories) to htdocs-20081125.tar

the backup directory. What command did you use? [Table 21-24]

3. Verify your tarfile contains xampp/lang/jp.php What command did you use? From where? [Table 1-4]

4. Delete and then restore xampp/lang/jp.php from the backup directory

What command did you use? [Table 9-12]

Page 44: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandSize can differ between tarfile and backed up file

Tarfiles Tarfile can be smaller than backed up file as it only

saves the date, not unused portion of data blocks Tarfile can be larger if backed up file is a sparse file Additional empty blocks can be added to tar version

Page 45: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Tarfiles Additional empty blocks can be added to tar version

tar commanddu size can differ between tarfile and backed up file

du report shows more disk space used than original for copy and tar extracts

original file

original file

ls command show same size for original, copy and tar extracts

Note: the –s option is to handle sparse files (discussed later)

Page 46: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Tarfiles Additional empty blocks can be added to tar version

[root@benji ~]# stat messages /var/log/messages sparse/messages nosparse/messages File: `messages' Size: 127538 Blocks: 272 IO Block: 4096 regular file<snipped> File: `/var/log/messages' Size: 127538 Blocks: 254 IO Block: 4096 regular file<snipped> File: `sparse/messages' Size: 127538 Blocks: 272 IO Block: 4096 regular file<snipped> File: `nosparse/messages' Size: 127538 Blocks: 272 IO Block: 4096 regular file<snipped>[root@benji ~]#

tar commandSize can differ between tarfile and backed up file

stat command shows copy and files extracted from tarfile have additional blocks which explains why file size is the same but disk usage is higher.

Page 47: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandsparse files

Sparse Files Null blocks (containing only zeroes) are not stored on

the disk Can be problematic if utilities don't recognize them

[root@benji ~]# cd /var/log[root@benji log]# ls -l lastlog-rw-r--r-- 1 root root 234476 Nov 22 05:18 lastlog

[root@benji log]# du -h lastlog16K lastlog

Note the reduced size of the file actually stored on the disk using du –h command

Page 48: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Sparse Files tar command without using the sparse option (-S) for

sparse file

tar commandsparse files

The tarfile has expanded all the null blocks increasing disk space usage

[root@benji ~]# cd /var/log[root@benji log]# tar cvf /root/lastlog.tar lastloglastlog[root@benji log]# cd /root[root@benji ~]# ls -l lastlog.tar-rw-r--r-- 1 root root 245760 Nov 22 05:19 lastlog.tar[root@benji ~]# du -h lastlog.tar248K lastlog.tar

[root@benji ~]# tar xvf lastlog.tarlastlog[root@benji ~]# ls -l lastlog-rw-r--r-- 1 root root 234476 Nov 22 05:18 lastlog[root@benji ~]# du -h lastlog240K lastlog

Page 49: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Sparse Files tar command using the sparse option (-S) with sparse

file

tar commandsparse files

[root@benji ~]# cd /var/log[root@benji log]# tar cSvf /root/lastlog2.tar lastloglastlog[root@benji log]# cd /root

[root@benji ~]# tar xvf lastlog2.tarlastlog[root@benji ~]# ls -l lastlog-rw-r--r-- 1 root root 234476 Nov 22 05:18 lastlog[root@benji ~]# du -h lastlog20K lastlog[root@benji ~]#

Using the -S option, the tar command handles the sparse file efficiently

Page 50: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandcompression

tar file(s) -C dirct vfx

tarfile

The z option uses gzip compresssion and the j option uses bzip2 compression

bzip2 is slower, but compresses moregzip is faster, but compreses less

Page 51: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandcompression

Backing up htdocs with no compression

Page 52: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandcompression

Post-compression using gzip of archive

Page 53: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandcompression

Post-compression using bzip2 of archive

Page 54: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandcompression

Using gzip compression option

Page 55: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandcompression

Using the bzip2 compression option

Page 56: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandcompression

[root@benji backup]# ls -Slrtotal 2049-rw-r--r-- 1 root root 340646 Nov 22 13:14 htdocs.tar.bz2-rw-r--r-- 1 root root 340646 Nov 22 13:18 htdocs2.tar.bz2-rw-r--r-- 1 root root 343748 Nov 22 13:13 htdocs.tar.gz-rw-r--r-- 1 root root 343760 Nov 22 13:15 htdocs2.tar.gz-rw-r--r-- 1 root root 706560 Nov 22 13:13 htdocs.tar[root@benji backup]#

Conclusions:• compression option slightly better than two steps• bzip2 compresses more that gzip

2 steps

Page 57: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandcompression

FYI, not specifying the z option still works when restoring a file

Page 58: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandcompression

FYI, not specifying the j option still works when restoring a file

Page 59: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Class Exercisetar command

1. Change to the /opt/lampp/htdocs directory.

2. Make four backups of htdocs into the /root directory using both compression options and using post compression with gzip and bzip2.a) -z option b) -j optionc) 2 steps with gzip commandd) 2 steps with bzip2 command

3. Verify your backup by deleting, restoring and viewing sample.html for each backup above

What commands did you use for 2a and 3? [Table 17-20]What commands did you use for 2b and 3? [Table 5-8]What commands did you use for 2c and 3? [Table 13-16]What commands did you use for 2d and 3? [Table 21-24]

Page 60: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandcompression

tar file(s)ct vfx

Backups can be made to devices as well

zj

Page 61: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandusing devices

[root@benji bin]# fdisk /dev/sda

Command (m for help): nFirst cylinder (582-652, default 582):Using default value 582Last cylinder or +size or +sizeM or +sizeK (582-652, default 652): +500M

Command (m for help): p

Disk /dev/sda: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System/dev/sda1 * 1 382 3068383+ 83 Linux/dev/sda2 383 447 522112+ 82 Linux swap / Solaris/dev/sda3 448 511 514080 83 Linux/dev/sda4 512 652 1132582+ 5 Extended/dev/sda5 512 549 305203+ 83 Linux/dev/sda6 550 556 56196 83 Linux/dev/sda7 557 581 200781 83 Linux/dev/sda8 582 643 497983+ 83 Linux

Command (m for help):

Make a 500 MB partition

Page 62: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandusing devices

Use partprobe so kernel will use new partition table

Command (m for help): x

Expert command (m for help): wThe partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.The kernel still uses the old table.The new table will be used at the next reboot.Syncing disks.[root@benji bin]# partprobe[root@benji bin]#

Page 63: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandusing devices

You don't need to backup socket files. They are created automatically by the kernel when needed

Change to the directory to back up. Note /dev/sda8 is not mounted

Page 64: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandusing devices

Restoring deleted file from backup archive on a device

Finding file in archive

Oops! …. file gets deleted

Viewing restored file

Page 65: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandExamples

Don't backup and restore /proc (this is real time kernel data) !!

Perform full backup of entire file tree

-p, --same-permissions, --preserve-permissions Keeps permissions of extracted files the same as the originals.

Page 66: CIS 90 - Lesson 14

CIS 90 - Lesson 14

tar commandExamples

Backup files in /opt after May 5, 1993

This allows differential and incremental backups to be done. Both types are based on a date. Either the last backup (incremental) or the last full backup (differential).

To do differential or incremental backups you will need a mechanism to track the dates or use a higher level backup program that makes use of tar.

Page 67: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Class Exercisetar command

1. Create a 500 MB partition on /dev/sda

2. Backup the entire /opt directory to this partition using tarWhat commands did you use? [Table 1-4]

3. Verify your backup by deleting, restoring and viewing sample.html for each backup aboveWhat commands did you use? [Table 9-12]

4. Delete the 500 MB partition

Page 68: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Class Exercisetar

On Opus, tar up you entire home directory. Use your own

logname to name the tarball:cdtar cvf logname.tar *

On your local vm, create a directory with the same name as your Opus logname and change into it.

mkdir lognamecd logname/scp [email protected]:*.tar .tar xvf logname.tar

Page 69: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Wrap up

Page 70: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Next Class

Project is due next week!

Page 71: CIS 90 - Lesson 14

CIS 90 - Lesson 14

Backup


Recommended