当前位置: 技术问答>linux和unix
200rmb求做Bourne shell script小程序,简单的英文版.
来源: 互联网 发布时间:2016-04-11
本文导语: [b][b]Write a shell script (to run on the Bourne shell) to copy all the files from the directories named dir1 and dir2 to a new directory named dir3. (1). In the beginning of your script you need to check that the directories dir1 and dir2 exi...
[b][b]Write a shell script (to run on the Bourne shell) to copy all the files from the
directories named dir1 and dir2 to a new directory named dir3.
(1). In the beginning of your script you need to check that the directories dir1 and
dir2 exist under the current directory (if not, your script displays an error message
and then exits).
(2). All the three directory names are supplied as arguments, and the new directory
dir3 must not currently exist (ie, the creation of dir3 is part of the script).
(3). The script first copies all the files from dir1 into dir3, overwriting any existing
files in dir3 from dir1.
(4). The script then copies every file from dir2 to dir3 subject to these conditions: if
the file from dir2 is not already present in dir3 or if the dir2 file is newer than the
same dir3 file it will overwrite its namesake in dir3.
(5). Remove all the temporary files (if any) at the end of your script.
Hint: you probably need to research these UNIX commands: find, set, cp. You
should note that the cp command without any option does not preserve certain
attributes (such as ownership and timestamps).
Your script for this task must be named cp2.sh. Make sure that your script is userfriendly
and follows common sense. The following is a sample output of the script.
Task B (20 marks)
Write a shell script (to run on the Bourne shell) that runs an infinite loop to
monitor which users on a denial list have logged into the UNIX system more
than once.
(1). The denial list must be stored in a text file named user.deny which lists which
users are not allowed multiple logins, specified by one username per line.
(2). In the beginning of the script you need to check that the user.deny file exists
under the current directory, and if not, your script displays a message to say so and
then exits.
(3). Every 3 seconds, the script must display a warning message to report who have
logged in multiple times and who are on the denial list. Display the user’s full name
instead of his/her username in the warning message.
(4). It’s unnecessary for your script to handle the situation where a user logs in and
then logs off immediately (i.e. within a 5 second interval).
KXT204 Assignment 1, 2008
Page 3 of 8
Your script for this task must be named mlog.sh. The following is a sample output
of the script (It is OK if the script leaves behind temporary files when it is finally
interrupted). The $ is the shell prompt.
Task C (50 marks)
Dominion Consulting in Sydney needs a shell script (to run on the Bourne shell) to
maintain its employee records file, which contains the following information about
each employee: telephone number (8 digits, first digit non-zero), family name
(alphabetic characters), first name (alphabetic characters), department
number (2 digits), and job title (alphabetic characters). This script should let users
add, delete, search for, and display specific employee information.
(1). Create a text file named records containing the following records with fields
delimited by colons:
95671660:Jones:Sarah:45:sales manager
93272658:Smith:John:43:technical manager
98781987:Williams:Nick:35:computer officer
99893878:Brown:Sarah:12:electrician
95673456:Couch:David:26:chef
95437869:Anderson:Sarah:19:CEO
(2). In the beginning of your script you need to check to see whether the required text
file (records) actually exists under the current directory (if not, your script displays
a message and then exits).
(3). Your script (must be named menu.sh) will present a menu of operations that a
user may choose from. Among other tasks, these operations automate the process of
KXT204 Assignment 1, 2008
Page 4 of 8
1. Displaying all current employee records (formatted and sorted) on the screen.
Format: 5 columns, each left-justified, column order is family name, first
name, telephone number, department number and job title. Sorting: records
must be sorted by family name (ascending).
2. Searching for and displaying specific employee record(s) (search all fields,
ignoring case)
3. Adding new records to the records file.
4. Deleting records from the records file.
(4). Your script must produce the following menu:
Dominion Consulting Employees Info Main Menu
============================================
1 – Print All Current Records (formatted)
2 - Search for Specific Record(s)
3 - Add New Records
4 – Delete Records
Q - Quit
(5). After a user makes a selection and that the selected operation has been
completed, the menu must be displayed again so that the user can make another
selection.
(6). You must validate the employee details when adding a new record.
(7). A valid family name, first name and job title must be alphabetic characters and/or
spaces, but the first character must not be a space. The first digit of a valid phone
number (8-digit) must not be zero. A valid department number must only contain 2
digits.
You may need to investigate some of these UNIX commands: awk, sort, cut,
paste, sed, grep. You may also need to investigate some other UNIX commands.
Here is a sample output of your script. The $ is the shell prompt. The items in italics
are not part of the sample output. They are hints indicating how your script should
behave.
能做的谢谢,qq联系:77373996
这里贴的不太清楚......
directories named dir1 and dir2 to a new directory named dir3.
(1). In the beginning of your script you need to check that the directories dir1 and
dir2 exist under the current directory (if not, your script displays an error message
and then exits).
(2). All the three directory names are supplied as arguments, and the new directory
dir3 must not currently exist (ie, the creation of dir3 is part of the script).
(3). The script first copies all the files from dir1 into dir3, overwriting any existing
files in dir3 from dir1.
(4). The script then copies every file from dir2 to dir3 subject to these conditions: if
the file from dir2 is not already present in dir3 or if the dir2 file is newer than the
same dir3 file it will overwrite its namesake in dir3.
(5). Remove all the temporary files (if any) at the end of your script.
Hint: you probably need to research these UNIX commands: find, set, cp. You
should note that the cp command without any option does not preserve certain
attributes (such as ownership and timestamps).
Your script for this task must be named cp2.sh. Make sure that your script is userfriendly
and follows common sense. The following is a sample output of the script.
Task B (20 marks)
Write a shell script (to run on the Bourne shell) that runs an infinite loop to
monitor which users on a denial list have logged into the UNIX system more
than once.
(1). The denial list must be stored in a text file named user.deny which lists which
users are not allowed multiple logins, specified by one username per line.
(2). In the beginning of the script you need to check that the user.deny file exists
under the current directory, and if not, your script displays a message to say so and
then exits.
(3). Every 3 seconds, the script must display a warning message to report who have
logged in multiple times and who are on the denial list. Display the user’s full name
instead of his/her username in the warning message.
(4). It’s unnecessary for your script to handle the situation where a user logs in and
then logs off immediately (i.e. within a 5 second interval).
KXT204 Assignment 1, 2008
Page 3 of 8
Your script for this task must be named mlog.sh. The following is a sample output
of the script (It is OK if the script leaves behind temporary files when it is finally
interrupted). The $ is the shell prompt.
Task C (50 marks)
Dominion Consulting in Sydney needs a shell script (to run on the Bourne shell) to
maintain its employee records file, which contains the following information about
each employee: telephone number (8 digits, first digit non-zero), family name
(alphabetic characters), first name (alphabetic characters), department
number (2 digits), and job title (alphabetic characters). This script should let users
add, delete, search for, and display specific employee information.
(1). Create a text file named records containing the following records with fields
delimited by colons:
95671660:Jones:Sarah:45:sales manager
93272658:Smith:John:43:technical manager
98781987:Williams:Nick:35:computer officer
99893878:Brown:Sarah:12:electrician
95673456:Couch:David:26:chef
95437869:Anderson:Sarah:19:CEO
(2). In the beginning of your script you need to check to see whether the required text
file (records) actually exists under the current directory (if not, your script displays
a message and then exits).
(3). Your script (must be named menu.sh) will present a menu of operations that a
user may choose from. Among other tasks, these operations automate the process of
KXT204 Assignment 1, 2008
Page 4 of 8
1. Displaying all current employee records (formatted and sorted) on the screen.
Format: 5 columns, each left-justified, column order is family name, first
name, telephone number, department number and job title. Sorting: records
must be sorted by family name (ascending).
2. Searching for and displaying specific employee record(s) (search all fields,
ignoring case)
3. Adding new records to the records file.
4. Deleting records from the records file.
(4). Your script must produce the following menu:
Dominion Consulting Employees Info Main Menu
============================================
1 – Print All Current Records (formatted)
2 - Search for Specific Record(s)
3 - Add New Records
4 – Delete Records
Q - Quit
(5). After a user makes a selection and that the selected operation has been
completed, the menu must be displayed again so that the user can make another
selection.
(6). You must validate the employee details when adding a new record.
(7). A valid family name, first name and job title must be alphabetic characters and/or
spaces, but the first character must not be a space. The first digit of a valid phone
number (8-digit) must not be zero. A valid department number must only contain 2
digits.
You may need to investigate some of these UNIX commands: awk, sort, cut,
paste, sed, grep. You may also need to investigate some other UNIX commands.
Here is a sample output of your script. The $ is the shell prompt. The items in italics
are not part of the sample output. They are hints indicating how your script should
behave.
能做的谢谢,qq联系:77373996
这里贴的不太清楚......
|
第一题做出来了,后面两题还没时间做,晚上回去有时间再看看.
[code=BatchFile]
#!/bin/sh
#######################################
#---------------cp2.sh----------------#
#-----------author:labing-------------#
#------------2008-08-28---------------#
if [ $# -ne 3 ]
then
echo "Usage:$0 "
exit 1
fi
if ! [ -d $1 ]
then
echo "$1 directory is not exist."
exit 2
elif ! [ -d $2 ]
then
echo "$2 directory is not exist."
exit 3
fi
if [ -d $3 ]
then
echo "$3 directory has been exist."
exit 3
fi
#create directory
mkdir $3
#copy files from first source directory to destination directory
for file in `ls $1`
do
cp $1/$file $3/$file
done
#copy files from second source directory to destination directory
for file in `ls $2`
do
#if the file is already exist,then update it when source file is newer
if [ -f $3/$file ]
then
cp -u $2/$file $3/$file
elif ! [ -f $3/$file ]
then
cp $2/$file $3/$file
fi
done
[/code]
[code=BatchFile]
#!/bin/sh
#######################################
#---------------cp2.sh----------------#
#-----------author:labing-------------#
#------------2008-08-28---------------#
if [ $# -ne 3 ]
then
echo "Usage:$0 "
exit 1
fi
if ! [ -d $1 ]
then
echo "$1 directory is not exist."
exit 2
elif ! [ -d $2 ]
then
echo "$2 directory is not exist."
exit 3
fi
if [ -d $3 ]
then
echo "$3 directory has been exist."
exit 3
fi
#create directory
mkdir $3
#copy files from first source directory to destination directory
for file in `ls $1`
do
cp $1/$file $3/$file
done
#copy files from second source directory to destination directory
for file in `ls $2`
do
#if the file is already exist,then update it when source file is newer
if [ -f $3/$file ]
then
cp -u $2/$file $3/$file
elif ! [ -f $3/$file ]
then
cp $2/$file $3/$file
fi
done
[/code]
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。