SlideShare a Scribd company logo
1 of 20
The Korn Shell is the UNIX shell (command execution program,
often called a command interpreter) that was developed by
David Korn of Bell Labs as a comprehensive, combined version
of other major UNIX shells. Incorporating all the features of the
C shell (csh) and the Tab C-shell (tcsh) with the script language
features similar to that of the Bourne Shell, the Korn Shell is
considered the most efficient shell. Korn, Bourne, and C are the
3 most commonly used UNIX shells. You will be using the Korn
Shell (ksh) for this project in which you will be writing shell
script files.
1.
Begin by executing the following command from a terminal
session in your Ubuntu system:
sudo apt-get install ksh
You will immediately be asked to enter your password
(csci345). This will install the Korn shell into your Ubuntu
system on your PC or Mac for use in this project. Simply type
ksh
and to go into the Korn Shell (your system prompt will change
to $ only) and then enter CTRL-D to exit out of it (your default
system prompt of
[email protected]
:~$ will re-appear).
As you go through this exercise and start writing shell scripts,
you will learn some additional troubleshooting tips to help you
navigate through the Korn Shell (ksh).
Keep track of some of these tips (5 of them) and put them into
a Word document in a list format with explanations (at least 150
words in current APA format). Make sure that these are
different from those mentioned in the textbook.
2.
Do some research on what the Korn Shell is about and what it
has to offer. Provide some basic information (3–5 key points) in
a short report (at least 150 words in current APA format) and
compile it into the same Word document as above and submit it
with this project. Also, provide 5–7 positive features of the
Korn Shell (ksh) in the same report (at least 150 words in
current APA format) in a list. Below are 3 websites that can
assist you in this effort. You will need at least 2 external
references for this short report (in addition to your textbook):
-
http://kornshell.com/
-
http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml
-
http://www.bolthole.com/solaris/ksh.html
There are many other websites out there that will give you
additional help, if needed. Take a look at the ksh shell script
below. There are 3 versions of essentially the same program,
which is a wrapper to edit a file under SCCS version control.
The basic task is to use the sccs command to “check out” a file
under version control and then automatically edit the file. The
script will then be used by users who may not be particularly
advanced UNIX users. Hence, the need for a wrapper script.
While the basic functionality is the same across all versions, the
differences in safety and usability between the first version and
the last (4th) version are worth noting. The first one is
extremely bad: it would be written by someone who has just
picked up a book on shell scripting and has decided, “I’m a
programmer now.”
#!/bin/ksh
sccs edit $1
if [ "$EDITOR" = "" ] ; then
EDITOR=vi
fi
$EDITOR $1
This version makes somewhat of an attempt to be user-friendly
by having a check for an environmental variable EDITOR
setting and using it, if available; however, there are no
comments, no error checking, and no help for the user at all.
The second one is an improvement, showing some consideration
to potential users by having safety checks.
#!/bin/ksh
# Author: Name Here
if [ $# -lt 1 ] ; then
print "This program will check out a file, or files, with
sccs"
exit 1
fi
# set EDITOR var to "vi" if not already set
EDITOR=${EDITOR:-vi}
sccs edit
[email protected]
$EDITOR
[email protected]
This is a step above the prior version. It accepts multiple files
as potential arguments. It is always nice to be flexible about the
number of files your scripts can handle. It also has a usage
message if the script is called without arguments. Plus, it is
always a good idea to put your name in as well. Unfortunately,
there is still quite a bit lacking as you can tell by comparing it
to the next version. The third one is a good, solid version; it is a
positive role model for your scripts.
#!/bin/ksh
# SCCS editing wrapper, version 0.3
# Author - Sys Admin
# Usage: see usage() function, below
usage(){
print sedit - a wrapper to edit files under SCCS
print "usage: sedit file {file2 ...}"
}
# Set EDITOR var to "vi" if not already set to something
EDITOR=${EDITOR:-vi}
# Could already be in path, but it doesn’t hurt to add it again.
# adjust as needed, if your sccs lives somewhere else
SCCSBIN=/usr/ccs/bin
if [ ! -x $SCCSBIN/sccs ] ; then
print ERROR: sccs not installed on this machine. Cannot
continue.
usage
exit 1
fi
PATH=$SCCSBIN:$PATH
if [ $# -lt 1 ] ; then
usage
print ERROR: no files specified
exit 1
fi
# Yes, I could use "sccs edit
[email protected]
" and check for a single error, but # this approach allows for
finer error reporting
for f in
[email protected]
; do
sccs edit $f
if [ $? -ne 0 ] ; then
print ERROR checking out file $f
if [ "$filelist" != "" ] ; then
print "Have checked out $filelist"
fi
exit 1
fi
filelist="$filelist $f"
done
$EDITOR $filelist
if [ $? -ne 0 ] ; then
print ERROR: $EDITOR returned error status
exit 1
fi
Here are some nice things to note with this script:
·
Sets special variables at the top of the script in a unified place;
·
Paranoid checks about EVERYTHING;
·
Returns an error status from the script on non-clean exit
condition (“exit 1” vs. “exit”); and
·
Use of comments. Not only does he/she specify what he/she is
doing, he/she clarifies what she/she is NOT doing and why.
3.
Now that you have the Korn Shell (ksh) installed and have
learned more about the language itself, it is time to do some
programming:
a.
Write a Korn shell script that accepts exactly 1 command line
argument that must be a positive integer. The script will print a
comma separated list of integers, all on the same line, starting
with the initial command line value and decreasing it by one-to-
one. The last printed value must not be followed by a comma.
Do not write this script to be executed interactively.
Requirements:
The script must be to handle the following error situations:
1.
Incorrect number of arguments and
2.
Non-positive arguments.
The script file name must be:
printnum.sh
The script permissions must be 705 (show in your Word
document).
Sample Output (provide yours in same Word document)
Sunny Day Scenarios:
[email protected]
:~$
sh printnum.sh 3
3, 2, 1
[email protected]
:~$
[email protected]
:~$
sh printnum.sh 10
10, 9, 8, 7, 6, 5, 4, 3, 2, 1
[email protected]
:~$
Rainy Day Scenarios:
[email protected]
:~$
sh printnum.sh
error: program must be executed with 1 argument. usage:
printnum.sh value (where value >= 1)
[email protected]
:~$
sh printnum.sh 2 5
error: program must be executed with 1 argument. usage:
printnum.sh value (where value >= 1)
[email protected]
:~$
sh printnum.sh -1
error: argument must be a positive number. usage: printnum.sh
value (where value >= 1)
Add at least 2 more scenarios in your Word document.
b.
Write a Korn shell script that will determine which file in a
directory has the maximum number of lines (this may be
different than the file that has the maximum number of bytes).
After determining the file with the maximum number of lines,
the script will print out the name of the file and the number of
lines. The script must only focus on files and ignore
subdirectories. The command
wc
may be helpful. Do not write this script to be executed
interactively.
Requirements:
·
The script must allow either no arguments or 1 argument.
1.
If zero arguments are specified, the script by default will
examine the files in the current directory.
2.
If 1 argument is specified, the argument must be the name of a
directory. The script will then examine the files in the specified
directory.
The script must be able to handle the following error
conditions:
1.
More than 1 argument is specified.
2.
The specified argument is not a directory.
The script file name must be:
maxlines.sh
The script permissions should be 705
Sample Output (provide yours in same Word document)
Sunny Day Scenarios
(Note: output depends on current directory and may not match
the values below):
[email protected]
:~$
sh maxlines.sh
File maxlines.sh has maximum number lines (36 lines).
[email protected]
:~$
sh maxlines.sh /etc
File mime.types has the maximum lines with 827 lines.
Rainy Day Scenarios:
[email protected]
:~$
sh maxlines.sh junk
error: argument must be a directory usage: maxlines.sh
[directory]
[email protected]
:~$
sh maxlines.sh junk trash
error: can only use 0 or 1 arguments. usage: maxlines.sh
[directory]
Add at least 2 more scenarios in your Word document.
c.
Create a search utility by writing 2 Korn Shell scripts named
srchfile.sh
and
srch.sh
,
respectively. The script
srchfile.sh
will list all occurrences of a string found in a file. The script
srch.sh
will list all occurrences of a string in a file or all files in a
specified directory. Actually,
srch.sh
will use the script
srchfile.sh
as if it were just another UNIX command to perform the actual
search in a file. In other words, the script
srch.sh
needs to be able to use the script
srchfile.sh
. Therefore, this assignment recommends that the first script
created be the
srchfile.sh
script. The script
srch.sh
calls the
srchfile.sh
script.
Requirements:
Part 1
Description.
The shell script
srchfile.sh
must accept 2 command line arguments.
1.
The script shall first print the name of the file being searched.
2.
If there are one more instances of the string in the file, the
script shall print each line that contains the matching string,
along with the line number of the file.
You may use the UNIX command
grep
in your script to do the actual search. In fact,
grep
can even print the line number if used with the appropriate
option (see man page for
grep
).
If the user enters more or fewer than the required number of
arguments, the script shall produce an error message and stop.
The first argument shall represent the string to be searched.
The second argument shall represent the name of the file to be
searched. If the second argument is not a file, the script shall
produce an error message and stop.
The script file name must be:
srchfile.sh
.
The script permissions must be 705
Sample Output (provide yours in same Word document)
In the Sunny Day Scenario
, the
srchfile.sh
script is invoked searching for string root pattern in file passwd
in the /etc directory:
[email protected]
:~$
sh srchfile.sh root /etc/passwd
------ File = /etc/passwd ------
1:root:x:0:0:root:/root:/bin/bash
In the Rainy Day Scenario
, script
srchfile.sh
is invoked with only 1 command line argument:
[email protected]
:~$
sh srchfile.sh xxxx
error: must provide 2 arguments
usage: sh srchfile.sh search-pattern file
In the Rainy Day Scenario
, script
srchfile.sh
is invoked with second command line argument /etc., which is
a directory rather than a file:
[email protected]
:~$
sh srchfile.sh xxxx /etc
error: second argument must be a file
usage: ./srchfile.sh search-pattern file
Add at least 2 more scenarios in your Word document.
Part 2
Description.
Now, write a second Korn Shell script named
srch.sh.
The
srch.sh
script will call the
srchfile.sh
script to perform a specific task and accept 2 command line
arguments. The first argument shall be a string (pattern) found
in the file being searched. The second command line argument
shall be the name of a file or a directory.
Requirements:
The second argument represents either the name of the file to be
searched or a directory. If a directory is entered, then all files in
the directory shall be searched.
The script
srch.sh
shall use the script
srchfile.sh
to search for the string in a given file. If the second argument
is a directory, then
srch.sh
will invoke
srchfile.sh
repeatedly in a loop.
If the user enters more or fewer than the required number of
arguments, the script shall produce an error message and stop.
The script file name must be:
srch.sh
.
The script permissions must be 705.
Sample Output (provide yours in same Word document)
Sunny Day Scenario
, the
srch.sh
script searching for string root in the file /etc/passwd:
[email protected]
:~$
sh srch.sh root /etc/passwd
------ File = /etc/passwd ------
1:root:x:0:0:root:/root:/bin/bash
Rainy Day Scenario
, script
srch.sh
is invoked with only 1 command line argument:
[email protected]
:~$
sh srch.sh root
error: must provide 2 arguments
usage: sh srch.sh search-pattern file
Rainy Day Scenario
, script
srch.sh
is invoked with 3 command line arguments:
[email protected]
:~$
sh srch.sh root1 root2 root3
error: must provide 2 arguments
usage: sh srch.sh search-pattern file
Add at least 3 more scenarios in your Word document.
d.
In this exercise, you are to write a Korn shell script that spawns
5 processes and then kills them.
Requirements.
This homework assignment requires the creation of 2 Korn shell
scripts; 1 script shall be named
simple_script.sh
and the main script will be named
process.sh.
The source code for
simple_script.sh
is given to you below.
Simple_script.sh script
Create a small shell script file called
simple_script.sh
with the following contents:
echo “I am simple_script.sh with process ID $$” sleep 5
The
simple_script.sh
script file name must be:
simple_script.sh
.
Try running
simple_script.sh
at the command line; it will print out its process ID and then
sleep for 5 seconds before terminating. Each time you run the
script, it will have a different process ID.
process.sh script
Design your script named
process.sh
as follows:
Have your script create 5 instances of
simple_script.sh
in the background. Each time the script
process.sh
creates an instance of
simple_script.sh
, the
shell variable $! in
process.sh
will contain the process ID of the latest
simple_script.sh
script.
After your
process.sh
script has created 5 instances of
simple_script.sh
, let your
process.sh
script sleep for 1 second and then let your
process.sh
script start killing the processes using the process ID obtained
from $! (see man page for
kill
command).
Your script must only start killing processes AFTER it has
created ALL 5 instances of
simple_script.sh
(i.e., DO NOT create
simple_script.sh
process 1. Kill it and then create process 2, kill it and so on).
You MUST use a shell array for the
process.sh
script. Use the shell array to store the process IDs of the
simple_script.sh
processes.
The script file name must be:
process.sh
The script permissions must be 705.
Sample Output (provide yours in same Word document)
Sunny Day Scenarios (add here) …
Rainy Day Scenarios (add here) …
Below is a sample of the output messages from
process.sh
(NOTICE the order of how the scripts are created and
destroyed in the same order):
[email protected]
:~$
sh
process.sh
I am simple_script.sh with process ID 12301
I am simple_script.sh with process ID 12302
I am simple_script.sh with process ID 12305
I am simple_script.sh with process ID 12307
I am simple_script.sh with process ID 12309
process is killing process 12301
process is killing process 12302
process is killing process 12305
process is killing process 12307
process is killing process 12309
Add at least 2 scenarios in your Word document.
·
·
Submit a zip file with all Korn Shell script files for step 3, parts
a–d, and submit your Word document for steps 1–3 (scenarios).
The Korn Shell is the UNIX shell (command execution program, often c.docx

More Related Content

Similar to The Korn Shell is the UNIX shell (command execution program, often c.docx

Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdfharikrishnapolaki
 
Shell & Shell Script
Shell & Shell ScriptShell & Shell Script
Shell & Shell ScriptAmit Ghosh
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script Amit Ghosh
 
Basic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualBasic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualKuntal Bhowmick
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02duquoi
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linuxkishore1986
 
Linux introductory-course-day-1
Linux introductory-course-day-1Linux introductory-course-day-1
Linux introductory-course-day-1Julio Pulido
 
CSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docxCSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docxmydrynan
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1tutorialsruby
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1tutorialsruby
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.pptmugeshmsd5
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linuxrowiebornia
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptxDavidMaina47
 

Similar to The Korn Shell is the UNIX shell (command execution program, often c.docx (20)

Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdf
 
Shell & Shell Script
Shell & Shell ScriptShell & Shell Script
Shell & Shell Script
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script
 
UnixShells.ppt
UnixShells.pptUnixShells.ppt
UnixShells.ppt
 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
 
Basic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualBasic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manual
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
Linux introductory-course-day-1
Linux introductory-course-day-1Linux introductory-course-day-1
Linux introductory-course-day-1
 
Unixshellscript 100406085942-phpapp02
Unixshellscript 100406085942-phpapp02Unixshellscript 100406085942-phpapp02
Unixshellscript 100406085942-phpapp02
 
Shellscripting
ShellscriptingShellscripting
Shellscripting
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
CSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docxCSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docx
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
 
Unix
UnixUnix
Unix
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptx
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptx
 

More from SUBHI7

The material for this moduleweek has led us from Europe, through fi.docx
The material for this moduleweek has led us from Europe, through fi.docxThe material for this moduleweek has led us from Europe, through fi.docx
The material for this moduleweek has led us from Europe, through fi.docxSUBHI7
 
The media informs many viewers of deviance and crime, victims of cri.docx
The media informs many viewers of deviance and crime, victims of cri.docxThe media informs many viewers of deviance and crime, victims of cri.docx
The media informs many viewers of deviance and crime, victims of cri.docxSUBHI7
 
The midterm is already late.  I would like to submit ASAP.Illust.docx
The midterm is already late.  I would like to submit ASAP.Illust.docxThe midterm is already late.  I would like to submit ASAP.Illust.docx
The midterm is already late.  I would like to submit ASAP.Illust.docxSUBHI7
 
The major assignment for this week is to compose a 900-word essay co.docx
The major assignment for this week is to compose a 900-word essay co.docxThe major assignment for this week is to compose a 900-word essay co.docx
The major assignment for this week is to compose a 900-word essay co.docxSUBHI7
 
The minimum length for this assignment is 1,200 wordsMust use APA .docx
The minimum length for this assignment is 1,200 wordsMust use APA .docxThe minimum length for this assignment is 1,200 wordsMust use APA .docx
The minimum length for this assignment is 1,200 wordsMust use APA .docxSUBHI7
 
The Military•Select three characteristics of the early America.docx
The Military•Select three characteristics of the early America.docxThe Military•Select three characteristics of the early America.docx
The Military•Select three characteristics of the early America.docxSUBHI7
 
The minimum length for this assignment is 2,000 wordsDiscoveries.docx
The minimum length for this assignment is 2,000 wordsDiscoveries.docxThe minimum length for this assignment is 2,000 wordsDiscoveries.docx
The minimum length for this assignment is 2,000 wordsDiscoveries.docxSUBHI7
 
The Mini Project Task Instructions Read about validity and reliab.docx
The Mini Project Task Instructions Read about validity and reliab.docxThe Mini Project Task Instructions Read about validity and reliab.docx
The Mini Project Task Instructions Read about validity and reliab.docxSUBHI7
 
The Mexican ceramics folk-art firm signs a contract for the Mexican .docx
The Mexican ceramics folk-art firm signs a contract for the Mexican .docxThe Mexican ceramics folk-art firm signs a contract for the Mexican .docx
The Mexican ceramics folk-art firm signs a contract for the Mexican .docxSUBHI7
 
The maximum size of the Layer 2 frame has become a source of ineffic.docx
The maximum size of the Layer 2 frame has become a source of ineffic.docxThe maximum size of the Layer 2 frame has become a source of ineffic.docx
The maximum size of the Layer 2 frame has become a source of ineffic.docxSUBHI7
 
The menu structure for Holiday Travel Vehicles existing character-b.docx
The menu structure for Holiday Travel Vehicles existing character-b.docxThe menu structure for Holiday Travel Vehicles existing character-b.docx
The menu structure for Holiday Travel Vehicles existing character-b.docxSUBHI7
 
The marks are the actual grades which I got in the exam. So, if .docx
The marks are the actual grades which I got in the exam. So, if .docxThe marks are the actual grades which I got in the exam. So, if .docx
The marks are the actual grades which I got in the exam. So, if .docxSUBHI7
 
the main discussion will be Schwarzenegger and fitness,talk about ho.docx
the main discussion will be Schwarzenegger and fitness,talk about ho.docxthe main discussion will be Schwarzenegger and fitness,talk about ho.docx
the main discussion will be Schwarzenegger and fitness,talk about ho.docxSUBHI7
 
The minimum length for this assignment is 1,500 words. Cellular .docx
The minimum length for this assignment is 1,500 words. Cellular .docxThe minimum length for this assignment is 1,500 words. Cellular .docx
The minimum length for this assignment is 1,500 words. Cellular .docxSUBHI7
 
The Main Post needs to be 3-5 Paragraphs At a minimum, each stud.docx
The Main Post needs to be 3-5 Paragraphs At a minimum, each stud.docxThe Main Post needs to be 3-5 Paragraphs At a minimum, each stud.docx
The Main Post needs to be 3-5 Paragraphs At a minimum, each stud.docxSUBHI7
 
The main characters in Tay Garnetts film The Postman Always Rings.docx
The main characters in Tay Garnetts film The Postman Always Rings.docxThe main characters in Tay Garnetts film The Postman Always Rings.docx
The main characters in Tay Garnetts film The Postman Always Rings.docxSUBHI7
 
The minimum length for this assignment is 2,000 words and MUST inclu.docx
The minimum length for this assignment is 2,000 words and MUST inclu.docxThe minimum length for this assignment is 2,000 words and MUST inclu.docx
The minimum length for this assignment is 2,000 words and MUST inclu.docxSUBHI7
 
The mafia is a well organized enterprise that deals with drugs, pros.docx
The mafia is a well organized enterprise that deals with drugs, pros.docxThe mafia is a well organized enterprise that deals with drugs, pros.docx
The mafia is a well organized enterprise that deals with drugs, pros.docxSUBHI7
 
The minimum length for this assignment is 1,500 words. Be sure to ch.docx
The minimum length for this assignment is 1,500 words. Be sure to ch.docxThe minimum length for this assignment is 1,500 words. Be sure to ch.docx
The minimum length for this assignment is 1,500 words. Be sure to ch.docxSUBHI7
 
The madrigal was a very popular musical genre in the Renaissance. Ex.docx
The madrigal was a very popular musical genre in the Renaissance. Ex.docxThe madrigal was a very popular musical genre in the Renaissance. Ex.docx
The madrigal was a very popular musical genre in the Renaissance. Ex.docxSUBHI7
 

More from SUBHI7 (20)

The material for this moduleweek has led us from Europe, through fi.docx
The material for this moduleweek has led us from Europe, through fi.docxThe material for this moduleweek has led us from Europe, through fi.docx
The material for this moduleweek has led us from Europe, through fi.docx
 
The media informs many viewers of deviance and crime, victims of cri.docx
The media informs many viewers of deviance and crime, victims of cri.docxThe media informs many viewers of deviance and crime, victims of cri.docx
The media informs many viewers of deviance and crime, victims of cri.docx
 
The midterm is already late.  I would like to submit ASAP.Illust.docx
The midterm is already late.  I would like to submit ASAP.Illust.docxThe midterm is already late.  I would like to submit ASAP.Illust.docx
The midterm is already late.  I would like to submit ASAP.Illust.docx
 
The major assignment for this week is to compose a 900-word essay co.docx
The major assignment for this week is to compose a 900-word essay co.docxThe major assignment for this week is to compose a 900-word essay co.docx
The major assignment for this week is to compose a 900-word essay co.docx
 
The minimum length for this assignment is 1,200 wordsMust use APA .docx
The minimum length for this assignment is 1,200 wordsMust use APA .docxThe minimum length for this assignment is 1,200 wordsMust use APA .docx
The minimum length for this assignment is 1,200 wordsMust use APA .docx
 
The Military•Select three characteristics of the early America.docx
The Military•Select three characteristics of the early America.docxThe Military•Select three characteristics of the early America.docx
The Military•Select three characteristics of the early America.docx
 
The minimum length for this assignment is 2,000 wordsDiscoveries.docx
The minimum length for this assignment is 2,000 wordsDiscoveries.docxThe minimum length for this assignment is 2,000 wordsDiscoveries.docx
The minimum length for this assignment is 2,000 wordsDiscoveries.docx
 
The Mini Project Task Instructions Read about validity and reliab.docx
The Mini Project Task Instructions Read about validity and reliab.docxThe Mini Project Task Instructions Read about validity and reliab.docx
The Mini Project Task Instructions Read about validity and reliab.docx
 
The Mexican ceramics folk-art firm signs a contract for the Mexican .docx
The Mexican ceramics folk-art firm signs a contract for the Mexican .docxThe Mexican ceramics folk-art firm signs a contract for the Mexican .docx
The Mexican ceramics folk-art firm signs a contract for the Mexican .docx
 
The maximum size of the Layer 2 frame has become a source of ineffic.docx
The maximum size of the Layer 2 frame has become a source of ineffic.docxThe maximum size of the Layer 2 frame has become a source of ineffic.docx
The maximum size of the Layer 2 frame has become a source of ineffic.docx
 
The menu structure for Holiday Travel Vehicles existing character-b.docx
The menu structure for Holiday Travel Vehicles existing character-b.docxThe menu structure for Holiday Travel Vehicles existing character-b.docx
The menu structure for Holiday Travel Vehicles existing character-b.docx
 
The marks are the actual grades which I got in the exam. So, if .docx
The marks are the actual grades which I got in the exam. So, if .docxThe marks are the actual grades which I got in the exam. So, if .docx
The marks are the actual grades which I got in the exam. So, if .docx
 
the main discussion will be Schwarzenegger and fitness,talk about ho.docx
the main discussion will be Schwarzenegger and fitness,talk about ho.docxthe main discussion will be Schwarzenegger and fitness,talk about ho.docx
the main discussion will be Schwarzenegger and fitness,talk about ho.docx
 
The minimum length for this assignment is 1,500 words. Cellular .docx
The minimum length for this assignment is 1,500 words. Cellular .docxThe minimum length for this assignment is 1,500 words. Cellular .docx
The minimum length for this assignment is 1,500 words. Cellular .docx
 
The Main Post needs to be 3-5 Paragraphs At a minimum, each stud.docx
The Main Post needs to be 3-5 Paragraphs At a minimum, each stud.docxThe Main Post needs to be 3-5 Paragraphs At a minimum, each stud.docx
The Main Post needs to be 3-5 Paragraphs At a minimum, each stud.docx
 
The main characters in Tay Garnetts film The Postman Always Rings.docx
The main characters in Tay Garnetts film The Postman Always Rings.docxThe main characters in Tay Garnetts film The Postman Always Rings.docx
The main characters in Tay Garnetts film The Postman Always Rings.docx
 
The minimum length for this assignment is 2,000 words and MUST inclu.docx
The minimum length for this assignment is 2,000 words and MUST inclu.docxThe minimum length for this assignment is 2,000 words and MUST inclu.docx
The minimum length for this assignment is 2,000 words and MUST inclu.docx
 
The mafia is a well organized enterprise that deals with drugs, pros.docx
The mafia is a well organized enterprise that deals with drugs, pros.docxThe mafia is a well organized enterprise that deals with drugs, pros.docx
The mafia is a well organized enterprise that deals with drugs, pros.docx
 
The minimum length for this assignment is 1,500 words. Be sure to ch.docx
The minimum length for this assignment is 1,500 words. Be sure to ch.docxThe minimum length for this assignment is 1,500 words. Be sure to ch.docx
The minimum length for this assignment is 1,500 words. Be sure to ch.docx
 
The madrigal was a very popular musical genre in the Renaissance. Ex.docx
The madrigal was a very popular musical genre in the Renaissance. Ex.docxThe madrigal was a very popular musical genre in the Renaissance. Ex.docx
The madrigal was a very popular musical genre in the Renaissance. Ex.docx
 

Recently uploaded

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

The Korn Shell is the UNIX shell (command execution program, often c.docx

  • 1. The Korn Shell is the UNIX shell (command execution program, often called a command interpreter) that was developed by David Korn of Bell Labs as a comprehensive, combined version of other major UNIX shells. Incorporating all the features of the C shell (csh) and the Tab C-shell (tcsh) with the script language features similar to that of the Bourne Shell, the Korn Shell is considered the most efficient shell. Korn, Bourne, and C are the 3 most commonly used UNIX shells. You will be using the Korn Shell (ksh) for this project in which you will be writing shell script files. 1. Begin by executing the following command from a terminal session in your Ubuntu system: sudo apt-get install ksh You will immediately be asked to enter your password (csci345). This will install the Korn shell into your Ubuntu system on your PC or Mac for use in this project. Simply type ksh and to go into the Korn Shell (your system prompt will change to $ only) and then enter CTRL-D to exit out of it (your default system prompt of [email protected] :~$ will re-appear). As you go through this exercise and start writing shell scripts, you will learn some additional troubleshooting tips to help you navigate through the Korn Shell (ksh). Keep track of some of these tips (5 of them) and put them into
  • 2. a Word document in a list format with explanations (at least 150 words in current APA format). Make sure that these are different from those mentioned in the textbook. 2. Do some research on what the Korn Shell is about and what it has to offer. Provide some basic information (3–5 key points) in a short report (at least 150 words in current APA format) and compile it into the same Word document as above and submit it with this project. Also, provide 5–7 positive features of the Korn Shell (ksh) in the same report (at least 150 words in current APA format) in a list. Below are 3 websites that can assist you in this effort. You will need at least 2 external references for this short report (in addition to your textbook): - http://kornshell.com/ - http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml - http://www.bolthole.com/solaris/ksh.html There are many other websites out there that will give you additional help, if needed. Take a look at the ksh shell script below. There are 3 versions of essentially the same program, which is a wrapper to edit a file under SCCS version control. The basic task is to use the sccs command to “check out” a file under version control and then automatically edit the file. The script will then be used by users who may not be particularly advanced UNIX users. Hence, the need for a wrapper script. While the basic functionality is the same across all versions, the differences in safety and usability between the first version and
  • 3. the last (4th) version are worth noting. The first one is extremely bad: it would be written by someone who has just picked up a book on shell scripting and has decided, “I’m a programmer now.” #!/bin/ksh sccs edit $1 if [ "$EDITOR" = "" ] ; then EDITOR=vi fi $EDITOR $1 This version makes somewhat of an attempt to be user-friendly by having a check for an environmental variable EDITOR setting and using it, if available; however, there are no comments, no error checking, and no help for the user at all. The second one is an improvement, showing some consideration to potential users by having safety checks. #!/bin/ksh # Author: Name Here if [ $# -lt 1 ] ; then print "This program will check out a file, or files, with sccs" exit 1 fi # set EDITOR var to "vi" if not already set
  • 4. EDITOR=${EDITOR:-vi} sccs edit [email protected] $EDITOR [email protected] This is a step above the prior version. It accepts multiple files as potential arguments. It is always nice to be flexible about the number of files your scripts can handle. It also has a usage message if the script is called without arguments. Plus, it is always a good idea to put your name in as well. Unfortunately, there is still quite a bit lacking as you can tell by comparing it to the next version. The third one is a good, solid version; it is a positive role model for your scripts. #!/bin/ksh # SCCS editing wrapper, version 0.3 # Author - Sys Admin # Usage: see usage() function, below usage(){ print sedit - a wrapper to edit files under SCCS print "usage: sedit file {file2 ...}" } # Set EDITOR var to "vi" if not already set to something EDITOR=${EDITOR:-vi} # Could already be in path, but it doesn’t hurt to add it again. # adjust as needed, if your sccs lives somewhere else SCCSBIN=/usr/ccs/bin if [ ! -x $SCCSBIN/sccs ] ; then
  • 5. print ERROR: sccs not installed on this machine. Cannot continue. usage exit 1 fi PATH=$SCCSBIN:$PATH if [ $# -lt 1 ] ; then usage print ERROR: no files specified exit 1 fi # Yes, I could use "sccs edit [email protected] " and check for a single error, but # this approach allows for finer error reporting for f in [email protected] ; do sccs edit $f if [ $? -ne 0 ] ; then print ERROR checking out file $f if [ "$filelist" != "" ] ; then print "Have checked out $filelist" fi exit 1 fi filelist="$filelist $f" done $EDITOR $filelist if [ $? -ne 0 ] ; then print ERROR: $EDITOR returned error status exit 1 fi
  • 6. Here are some nice things to note with this script: · Sets special variables at the top of the script in a unified place; · Paranoid checks about EVERYTHING; · Returns an error status from the script on non-clean exit condition (“exit 1” vs. “exit”); and · Use of comments. Not only does he/she specify what he/she is doing, he/she clarifies what she/she is NOT doing and why. 3. Now that you have the Korn Shell (ksh) installed and have learned more about the language itself, it is time to do some programming: a. Write a Korn shell script that accepts exactly 1 command line argument that must be a positive integer. The script will print a comma separated list of integers, all on the same line, starting with the initial command line value and decreasing it by one-to- one. The last printed value must not be followed by a comma. Do not write this script to be executed interactively. Requirements:
  • 7. The script must be to handle the following error situations: 1. Incorrect number of arguments and 2. Non-positive arguments. The script file name must be: printnum.sh The script permissions must be 705 (show in your Word document). Sample Output (provide yours in same Word document) Sunny Day Scenarios: [email protected] :~$ sh printnum.sh 3 3, 2, 1 [email protected] :~$ [email protected] :~$ sh printnum.sh 10 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 [email protected] :~$ Rainy Day Scenarios:
  • 8. [email protected] :~$ sh printnum.sh error: program must be executed with 1 argument. usage: printnum.sh value (where value >= 1) [email protected] :~$ sh printnum.sh 2 5 error: program must be executed with 1 argument. usage: printnum.sh value (where value >= 1) [email protected] :~$ sh printnum.sh -1 error: argument must be a positive number. usage: printnum.sh value (where value >= 1) Add at least 2 more scenarios in your Word document. b. Write a Korn shell script that will determine which file in a directory has the maximum number of lines (this may be different than the file that has the maximum number of bytes). After determining the file with the maximum number of lines, the script will print out the name of the file and the number of lines. The script must only focus on files and ignore subdirectories. The command wc may be helpful. Do not write this script to be executed interactively.
  • 9. Requirements: · The script must allow either no arguments or 1 argument. 1. If zero arguments are specified, the script by default will examine the files in the current directory. 2. If 1 argument is specified, the argument must be the name of a directory. The script will then examine the files in the specified directory. The script must be able to handle the following error conditions: 1. More than 1 argument is specified. 2. The specified argument is not a directory. The script file name must be: maxlines.sh The script permissions should be 705 Sample Output (provide yours in same Word document) Sunny Day Scenarios (Note: output depends on current directory and may not match the values below):
  • 10. [email protected] :~$ sh maxlines.sh File maxlines.sh has maximum number lines (36 lines). [email protected] :~$ sh maxlines.sh /etc File mime.types has the maximum lines with 827 lines. Rainy Day Scenarios: [email protected] :~$ sh maxlines.sh junk error: argument must be a directory usage: maxlines.sh [directory] [email protected] :~$ sh maxlines.sh junk trash error: can only use 0 or 1 arguments. usage: maxlines.sh [directory] Add at least 2 more scenarios in your Word document. c. Create a search utility by writing 2 Korn Shell scripts named srchfile.sh and srch.sh , respectively. The script
  • 11. srchfile.sh will list all occurrences of a string found in a file. The script srch.sh will list all occurrences of a string in a file or all files in a specified directory. Actually, srch.sh will use the script srchfile.sh as if it were just another UNIX command to perform the actual search in a file. In other words, the script srch.sh needs to be able to use the script srchfile.sh . Therefore, this assignment recommends that the first script created be the srchfile.sh script. The script srch.sh calls the srchfile.sh script. Requirements: Part 1 Description. The shell script srchfile.sh must accept 2 command line arguments. 1. The script shall first print the name of the file being searched. 2.
  • 12. If there are one more instances of the string in the file, the script shall print each line that contains the matching string, along with the line number of the file. You may use the UNIX command grep in your script to do the actual search. In fact, grep can even print the line number if used with the appropriate option (see man page for grep ). If the user enters more or fewer than the required number of arguments, the script shall produce an error message and stop. The first argument shall represent the string to be searched. The second argument shall represent the name of the file to be searched. If the second argument is not a file, the script shall produce an error message and stop. The script file name must be: srchfile.sh . The script permissions must be 705 Sample Output (provide yours in same Word document)
  • 13. In the Sunny Day Scenario , the srchfile.sh script is invoked searching for string root pattern in file passwd in the /etc directory: [email protected] :~$ sh srchfile.sh root /etc/passwd ------ File = /etc/passwd ------ 1:root:x:0:0:root:/root:/bin/bash In the Rainy Day Scenario , script srchfile.sh is invoked with only 1 command line argument: [email protected] :~$ sh srchfile.sh xxxx error: must provide 2 arguments usage: sh srchfile.sh search-pattern file In the Rainy Day Scenario , script srchfile.sh is invoked with second command line argument /etc., which is a directory rather than a file: [email protected] :~$ sh srchfile.sh xxxx /etc error: second argument must be a file usage: ./srchfile.sh search-pattern file
  • 14. Add at least 2 more scenarios in your Word document. Part 2 Description. Now, write a second Korn Shell script named srch.sh. The srch.sh script will call the srchfile.sh script to perform a specific task and accept 2 command line arguments. The first argument shall be a string (pattern) found in the file being searched. The second command line argument shall be the name of a file or a directory. Requirements: The second argument represents either the name of the file to be searched or a directory. If a directory is entered, then all files in the directory shall be searched. The script srch.sh shall use the script srchfile.sh to search for the string in a given file. If the second argument is a directory, then srch.sh will invoke srchfile.sh repeatedly in a loop. If the user enters more or fewer than the required number of
  • 15. arguments, the script shall produce an error message and stop. The script file name must be: srch.sh . The script permissions must be 705. Sample Output (provide yours in same Word document) Sunny Day Scenario , the srch.sh script searching for string root in the file /etc/passwd: [email protected] :~$ sh srch.sh root /etc/passwd ------ File = /etc/passwd ------ 1:root:x:0:0:root:/root:/bin/bash Rainy Day Scenario , script srch.sh is invoked with only 1 command line argument: [email protected] :~$ sh srch.sh root error: must provide 2 arguments usage: sh srch.sh search-pattern file Rainy Day Scenario , script
  • 16. srch.sh is invoked with 3 command line arguments: [email protected] :~$ sh srch.sh root1 root2 root3 error: must provide 2 arguments usage: sh srch.sh search-pattern file Add at least 3 more scenarios in your Word document. d. In this exercise, you are to write a Korn shell script that spawns 5 processes and then kills them. Requirements. This homework assignment requires the creation of 2 Korn shell scripts; 1 script shall be named simple_script.sh and the main script will be named process.sh. The source code for simple_script.sh is given to you below. Simple_script.sh script Create a small shell script file called simple_script.sh
  • 17. with the following contents: echo “I am simple_script.sh with process ID $$” sleep 5 The simple_script.sh script file name must be: simple_script.sh . Try running simple_script.sh at the command line; it will print out its process ID and then sleep for 5 seconds before terminating. Each time you run the script, it will have a different process ID. process.sh script Design your script named process.sh as follows: Have your script create 5 instances of simple_script.sh in the background. Each time the script process.sh creates an instance of simple_script.sh , the shell variable $! in process.sh will contain the process ID of the latest simple_script.sh script.
  • 18. After your process.sh script has created 5 instances of simple_script.sh , let your process.sh script sleep for 1 second and then let your process.sh script start killing the processes using the process ID obtained from $! (see man page for kill command). Your script must only start killing processes AFTER it has created ALL 5 instances of simple_script.sh (i.e., DO NOT create simple_script.sh process 1. Kill it and then create process 2, kill it and so on). You MUST use a shell array for the process.sh script. Use the shell array to store the process IDs of the simple_script.sh processes. The script file name must be: process.sh The script permissions must be 705. Sample Output (provide yours in same Word document)
  • 19. Sunny Day Scenarios (add here) … Rainy Day Scenarios (add here) … Below is a sample of the output messages from process.sh (NOTICE the order of how the scripts are created and destroyed in the same order): [email protected] :~$ sh process.sh I am simple_script.sh with process ID 12301 I am simple_script.sh with process ID 12302 I am simple_script.sh with process ID 12305 I am simple_script.sh with process ID 12307 I am simple_script.sh with process ID 12309 process is killing process 12301 process is killing process 12302 process is killing process 12305 process is killing process 12307 process is killing process 12309 Add at least 2 scenarios in your Word document. · · Submit a zip file with all Korn Shell script files for step 3, parts a–d, and submit your Word document for steps 1–3 (scenarios).