This is my question, below the question is the template
Write and execute a Bourne shell script called homework
that will
From within the script, create three background processes:
a) (2 points) one that saves a long listing of your hidden files to a file named hiddenlist
b) (2 points) one that saves a full listing of the status of your current running processes to a file named pstat
c) (2 points) one that stores only the count of the number of words from the file homework2
into a file named wordcount
d) (1 point) issue a command to wait for ALL three background processes to complete.
e) (1 point) give the user a message stating that the process are completed
1.There are no variables.
-
Relevant commands, code, script, alogrithems.
The relevant command would be cat to create files the | to join commands
for a I would need ls -la
for b I would need ps
for c I would need wc
for d I would need wait
for e I would need echo
-
Here is one of the many attempts I have made to solve this problem, I have many more but don't want
to flood the forum with my failed attempts.
cat > hiddenlist | ls -la > hiddenlist
cat > pstat | ps > pstat
cat > wordcount | wc homework2 > wordcount
wait
echo �Background Processes complete�
- California State University Fullerton, Fullerton California USA Floyd Holiday CPSC253U
Please use CODE tags when displaying sample input, output, and code.
You should look at the man page for your shell (presumably man sh
for the Bourne shell). Look for the words "Background" and "background" in that man page for ways to run a process in the background and restrictions on what a background job can do. You don't seem to have anything in your script to run any processes in the background.
Also look for "Redirection" and "redirection" to see what > file
does when it is used as a complete command, and what it does when it is used as part of a larger command.
And look for "Pipeline" and "pipeline". Having two processes in a pipeline that redirect standard output to the same file creates a race condition that may make it impossible to determine which process writing to that file will actually store lasting data in that file.
Then take a look at the man page for the cat
utility. The command:
cat > file
doesn't necessarily create an empty file named file
; it depends entirely on what cat
reads from its standard input.
Is your understanding of part "a)" of your assignment that the output should include all of your files (including hidden files); or that the output should only include your hidden files?
Thank you for pointing me in the right direction. As it turns out the commands on the power point I was using were not compatible with my shell. I'm honestly not sure why, but I'm happy I got it going.
Shells read commands written in the shell programming language. The shell programming language has very special meanings for the single quote, double quote, and backquote characters. Power-point and other text formatting tools use things like opening and closing single quotes and opening and closing double quotes that are fine for humans reading text, but are not valid in the shell programming language.
Note also that the shell (and most other UNIX and Linux utilities) expect lines to be terminated by a <newline> character while Windows systems have utilities that expect lines to be terminated by a <carriage-return><newline> character pair. When preparing text to be processed on UNIX and Linux systems, be sure that whatever editor you choose uses <newline> as its line terminator.
I think the 'cat to create files' is misleading and nonsense in general. The > creats the file - no need for cat. And here is no need for a | either.
You run 3 simple commands in the background(!), and wait for them.