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 Clarifications #/bin/bash Must be the absolute first line in your script, otherwise it is meaningless Put before your name, and before anything else # will start a comment, so put in front of your name Always run your scripts to verify what they are doing before you turn them in
Take Home Assignment Clarifications This is longer than all other programs so far, so if you haven’t started yet, start ASAP Due at the beginning of lab on Thursday (6:00 pm) Hints: Awk can be treated like just another bash program, so you can make calls and awk programs inside your bash shell script Indent for readibility (Comment for understandability)
Once A File Is Gone, It’s Gone The only way to prevent data loss is to keep a recent copy somewhere safe Of course, the entire hard drive could fail, so to be safer you need it in multiple locations Other hard drives Backup tapes
Our System - RAID Redundant array of independent disks Every hour a process checks and stores away any difference in your directories and files Places these files in the.snapshot direcotry Located on one or more other drives
Tape Archive - tar Designed to store files onto a tape device Now used for for storing and collecting files anywhere Creates and maintains archives Commonly seen as XXXX.tar files Usage: tar [FLAGS] [FILES]
Common Flags -c Create an archive -f Specify file -x Extract an archive -t List an archive
Creating A tar Archive tar –cf backup.tar FILES tar –c FILES > backup.tar As always, if you use file redirection be careful Easy to overwrite
Example
Listing A tar Archive tar –tf backup.tar tar –t < backup.tar Will simply print out a list of all files located in that tar archive without changing them
Example
Extracting A tar Archive tar –x < backup.tar tar –xf backup.tar Will create all of the files in their respective directories Will overwrite any files that are there already, so be carefule
Example
Automatically Compressing A tar Archive -Z Runs zip automatically on all files -z Runs gzip automatically on all files Example: tar –czf compressed.tar.gz *.txt
The Most Common Usage Tarfile.tar.gz Referred to as a “tarball” Almost all Unix programs and packages are available in this form To extract them: tar –xzvf tarball.tar.gz
Example
Basic Printing In Unix The printers expect to be given a.ps file Postscript Other formats may or may not work or may come out ugly Pdf (Adobe Acrobat format) Ascii (Straight text)
lpr Directly feed a printer a ps file to print Usage: lpr [FLAGS] toPrint.ps Most common flag: -Pname Specifies the name of the printer to send it to Default is located in /etc/cups/lpoptions
lpq Prints out a list of all jobs waiting to be printed from a specific printer Each job has an associated job ID Usage: lpq [FLAGS] Most common usages: lpq lpq -Pname
Poor Example
lprm Used to remove jobs from the queue Usage: lprm [FLAGS] jobID Example: lprm –Pname 23
Always Remove Your Print Jobs That Don’t Print! Sometimes, the printers don’t work and people send jobs to the printers without knowing it These jobs hang around until the printers start working again, and then everything gets printed Your work could print out when you’re not there and someone else could take it
a2ps Convert ASCII files into the.ps format Usage: a2ps [FLAGS] asciiFile Examples: a2ps –o printMe.ps asciiFile a2ps –Pname asciiFile
pdf2ps Converts Pdf format files into.ps files Usage: pdf2ps input.pdf output.ps
Viewing ps, pdf, And Other Files gs Ghostscript A basic ps and pdf viewer gv Ghostview A more user friendly ps and pdf viewer xpdf A pdf viewer
Next Time Perl Programming Basics Syntax When would you use perl?
Quiz 2 Good Luck