Subject: Shell Scripting Practice A
File: practice-script-a
Create File practice-script-a that:
1. Accepts any number of userids on the command line
2. For each userid, display the userid, PID, CPU time, and
current command for each process owned by that userid
Your output should look similar to this example:
practice-script-a doug.jones
User: doug.jones PID: 8748 TIME: 00:00:00 COMMAND:
/usr/lib/systemd/systemd --user
User: doug.jones PID: 8749 TIME: 00:00:00 COMMAND: (sd-pam)
User: doug.jones PID: 8750 TIME: 00:00:00 COMMAND: sshd:
doug.jones@pts/5
User: doug.jones PID: 8751 TIME: 00:00:00 COMMAND: -bash
User: doug.jones PID: 10984 TIME: 00:00:00 COMMAND: vim
practice8
User: doug.jones PID: 11217 TIME: 00:00:00 COMMAND: sshd:
doug.jones@pts/29
User: doug.jones PID: 11218 TIME: 00:00:00 COMMAND: -bash
User: doug.jones PID: 12702 TIME: 00:00:00 COMMAND: sshd:
doug.jones@pts/31
User: doug.jones PID: 12703 TIME: 00:00:00 COMMAND: -bash
User: doug.jones PID: 14136 TIME: 00:00:00 COMMAND: vim q5a
3. Your script should use the "echo" command for output, the
"ps" command
to get the PID, TIME, and COMMAND information, and 'for' loops
with
variables to couple the information. There is no need for awk, sed,
vim,
or other utilities in this script, and you should avoid them.
Although the length of the script file is NOT a factor in your
grade,
you should expect the script to be 10 to 15 lines, plus any
additional
comments you add.
4. Your script should include a series of comments that
fully
describes your script, including the purpose of each line.
You
may use a separate comment block or include the comments on
each line of code.
Email 2
Subject: Shell Scripting Practice B
File: practice-script-b
Create File practice-script-b that:
1. Accepts a file name as the first argument
2. Accepts a list of directories (any number of
directories)
as the remaining arguments
3. Searches each directory (NO subdirectories) for the specified file
4. Each time the target file is found in one of the specified
directories:
(a) Display the full path name of the file
(b) Display the owner name of the file
(c) Display the permission of the file as an octal number
Example Command:
practice-script-b makefile . / /bin /home ~
Example Output:
makefile found in . (owner: glen.sasek, permission: 700)
5. Your script should use the 'find' command to view and print
the
file information (i.e. -printf with %h, %u, %m codes), and
you
should use a 'for' loop to control the 'find' command's
search
through the target directories. Be sure to remember to use
the -maxdepth option to prevent searching sub-directories.
As before, there is no need for awk, vim, sed, or any
other
utilities other utilities, and you should avoid them.
Although the length of the sript file is NOT a factor in your
grade,
you should expect the script to be 8 to 10 lines, plus any
additional
comments you add.
6. Your script should include a series of comments that
fully
describes your script, including the purpose of each line.
You
may use a separate comment block or include the comments on
each line of code.
practice-script-a.sh
**********************
#!/bin/bash
echo "User: $1" ps -eo pid,user,args c
for var_name in $(seq 1 20); do
ps -eo pid,user,args c
done
We are allowed to do only 4 exercise out of any given.
if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)
Get Answers For Free
Most questions answered within 1 hours.