Question

Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of...


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.

Homework Answers

Answer #1

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 :)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create shell scripts, each in its own .sh file. Please include a shebang line at the...
Create shell scripts, each in its own .sh file. Please include a shebang line at the top of the script as well as appropriate comments through out. Write a script that uses sed to replace all instances of the name "Lizzy" with "Elizabeth" in a text file. Save the updated text in a new file named after the original text file with "-formal" appended before the file extension, e.g. old.txt -> old-formal.txt. Test this script on the data-shell/writing/data text files....
5. Write a bash command that will display the name of every file on the Linux...
5. Write a bash command that will display the name of every file on the Linux system whose file contaent contains the string "doug.jones". The command must run in the background, must redirect standard error to /dev/null, and must redirect standard output to ~/out. 6. Write a bash command that will kill all of the even-numbered processes associated with your userid, and no other processes. 7. Write a bash command that will start the program /home/courses/140u-doug.jones/zombie_maker as a background process,...
The first script you need to write is login.sh, a simple script that you might run...
The first script you need to write is login.sh, a simple script that you might run when you first log in to a machine. We'll expand this script later, but for now it should include your name, username, hostname, current directory, and the current time. Here is some sample output to help guide you. Note that the bolded lines that start with "[user@localhost ~]$" are the terminal prompts where you type in a command, not part of the script. Of...
Name the script for.sh.  This script will create a shopping list. Ask the user to enter items...
Name the script for.sh.  This script will create a shopping list. Ask the user to enter items separated by a space. Read the list. Use a for loop to write (use echo) the items to a file called shopping_list. You should use >> to append the output to the file, so each time the script is run the list should get longer. After the for loop finishes, display (use cat) the contents of the shopping list with 1 item per line....
1- Create a new script that is called HW9.m and save it. The script will do...
1- Create a new script that is called HW9.m and save it. The script will do the following. Test your code for each of the cases and upload your script as a .m file. [15 points] a. Create a random integer numbers that goes from 0 to 5 and assign it to a variable y using rand and round commands. Hint: Note that rand function only creates random number between 0 and 1. You need to scale the values to...
Create a file consisting a group of 3 new user name’s and passwords in powershell, 1...
Create a file consisting a group of 3 new user name’s and passwords in powershell, 1 to a line. When you read in the line you’ll have to split the name and the password. a. Write a script in powershell that does the following i. Use get-content to retrieve the names and assign them to an array ii. Write a loop that prints out each of the user names. iii. Have your script create an account using localuser for each...
Description: You will develop a small "text-based shell utility" ("ts") for Unix (or similar OS). A...
Description: You will develop a small "text-based shell utility" ("ts") for Unix (or similar OS). A common complaint of the most-used UNIX (text) shells (Bourne, Korn, C) is that it is difficult to remember (long) file names, and type "long" command names. A "menu" type shell allows a user to "pick" an item (file or command)from a "menu". You will display a simple menu, the following is a suggestion (you may change format): Current Working Dir: /home/os.progs/Me It is now:...
Save your select statements as a script. Place the semicolon at the end of each SQL...
Save your select statements as a script. Place the semicolon at the end of each SQL statement. Please number your select statements from 1 to 8 in your script and comment out each number. Include your name and student number as a comment at the top of your script. The name of the script has to be Assignment1_JohnSmith. Instead of JohnSmith use your First Name and Last Name. Upload your script trough Blackboard. Use SQL Developer to create the My...
You are to create a hard link to one of your existing files on someone else's...
You are to create a hard link to one of your existing files on someone else's directory (or vice versa). In other words, you know that you can link a file within your own directories, but you can also have a link to one of your files on other areas of the unix system as long as you have permissions to write to that directory (in this case, your partner). Create a subdirectory called temp where you can place this...
Using a Linux terminal, write a script, called UnixHistory.sh, which will generate an abbreviated "tree" of...
Using a Linux terminal, write a script, called UnixHistory.sh, which will generate an abbreviated "tree" of the Unix and Unix like operating system ancestry. The data source, as always, can be found on Wikipedia: https://en.wikipedia.org/wiki/File:Unix_history.svg The Unix history begins with a directory named ResearchUnix that has two children: BSD and Commercial. BSD has two children FreeBSD and NextStep, NextStep has a single child directory: MacOSX. Commercial has one sub-directory named Solaris NOTE all the elements mentioned above are directories, created...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT