Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assignment 3 : ThAssignment 5 : Monitoring tools: an introduction to some of the UNIX administrative commands. In this exercise follow the directions for Assignments
Assignment : ThAssignment : Monitoring tools: an introduction to some of the UNIX administrative commands.
In this exercise follow the directions for Assignments and Part When a question is asked, put your answers in a file called: admin.docx. For answers consult the man pages and any other Internet sources you can find. Also append to this file the results of doing the following UNIX commandline steps on the lxcluster. Bear in mind that different UNIX systems will use variants for administrative come directions are similar to Assignment above.
Part :
Step :
Enter the umask command to determine your file creation mask; if not then set the umask to
Create a directory in a convenient place it will be removed later called temp
Execute the ls l command and note the permissions on the new directory; compare to the file creation mask above
Change directory to temp
Create an empty file called newfile.txt with the shell command: $ newfile.txt
Execute the ls l command and note the permissions on the new file; compare to the file creation mask above
Step :
Change directory to the parent with $ cd
Attempt to remove the temp directory; note the failure message
Change directory back to temp
Change the permissions on newfile.txt using chmod to make the file writable by the group
Execute the ls l command to confirm
Change the permissions on newfile.txt to make it executable by the owner; execute the ls l command to confirm
Execute the newfile.txt with the newfiletxt command; note that nothing happens as it is empty
Delete the newfile.txt file
Step :
Create a shell script file called testscript.sh and add the following commands to itThe first line is a comment and instructs the shell to use the bash shell:
#binbash
echo listing
ls l
echo process status
ps
Make the testscript.sh file executable and readable by the user, the group, and others, but only writable by the owner; execute ls l to confirm
Run the script using the testscriptsh command
Step :
Create a new file called hardlink.txt with some text in it
hard link this file to a file called newfile.txt file using the ln command WITHOUT the s; see the man page for ln and get the order right!; confirm with ls l
Confirm that the two files have the same inode number with the ls i command
Remove with the rm command the hardlink.txt file; confirm with the ls li command that newfile.txt is still around with the same inode number
Create a file called simlink.txt symbolically linked using the ln s command to newfile.txt; confirm using ls l note that symlink.txt is NOT empty and does NOT have the same number of bytes as the newfile.txt
execute the command: cat symlink.txt to verify that it has the same contents as newfile.txt
Remove the newfile.txt file; confirm with ls l
Execute the following command to determine symlink.txts status: file symlink.txt
Remove all files in the temp directory interactively using the rm i command; confirm with ls l
Change directory to the parent directory and remove the temp directory; confirm with ls l
Part :
Write a program using the standard library IO functions fopen fread, fwrite, fclose, ferror, feof, and fflush to read a text file and search it for a string specified on the command line in each line of an input file whose name is also specified on the command line; if the string is found substitute another string also specified on the command line ONLY ONCE on the line.
Write the output with the substitutions to the stdout and write any errors to the stderr. The command line should have the form:
assign infilename string string
Be sure to check that the argc before proceeding.
So for the command:
assign infilename test TESTED
where the infilename file contains:
This is a test file
for assignment
It is to be tested thoroughly.
It substitutes a string for another uniformly
while reading a file opened
via the standard library.
And this is another test for testing.
Then the output to the stdout should be:
This is a TESTED file
for assignment
It is to be TESTEDed thoroughly.
It substitutes a string for another uniformly
while reading a file opened
via the standard library.
And this is another TESTED for testing.
substitutions made
Note that the second occurrence of test in the word testing is NOT substituted.
You will want to read the input file one line at a time into a buffer and then search the buffer for the first occurrence of stringif any; you may want to make use of strncmp You do not have to open an output file in your program; if you write the substituted text to the stdout you can save its output in a text file with a command like:
$ assign infilename string string outfilename
In addition, keep a count of the total number of substitutions made and display that number on the stderr at the end of execution.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started