The purpose of this programming assignment is to test your ability to create [bash] shell scripts to solve problems not exactly solved by common *nix tools.
First make sure you've read all of Chapters 8 and 10 from the *nix book.
One task often desired by *nix users and administrators alike is that of process tracking. In other words, what users are running what processes on the system right now?
You'll create a script in bash shell to list all processes currently running grouped by the processes' owners. If given a particular user(s), just list the processes that user has running.
If you are not given a particular user(s), however, create a menu of the users who own currently running processes with an 'all' option added at the end of the menu and prompt the script executer for whose processes to list. (Also allow them to quit without selecting anyone — maybe they just wanted to see who was running anything currently...*shrug*)
So, for example, should your script be called with a particular user, you might see a list like this:
$ proclist jjames jjames is currently running: ssh gvim CPP g++
As a special case, watch out for users who aren't currently running any processes!
$ proclist notauser notauser is currently running: NOTHING
And, perhaps even special treatment of the current user:
$ proclist `whoami` YOU are currently running: ssh
(Although the login status/process doesn't seem to be handled entirely consistently on mars. *shrug*)
Notice that the script doesn't list itself to the executer since we assume they know they are running it. *smile* However, if someone else where running the script, it would appear in their list:
$ proclist dkobler dkobler is currently running: ssh proclist
A sample of use from the menu form might be:
$ proclist Processes are currently being run by: 1) dkobler 2) jjames 3) YOU 4) a_notherstudent 5) ALL Whose processes to list?
Use as many built-in tools as you can to collect the necessary information from around the system and process it. If you cannot think of a tool, check Part VI of your *nix book first before coding out lots of processing in bash shell. (Trust me...)
I would suggest that you'll be using at least ps, grep, whoami, and cut. (But that is just off the top of my head. Others may also prove useful! Don't sell a good tool short just because the teacher didn't mention it... *grin*)
Although ps is your main tool here, keep in mind that not all ps implementations are created equal. Try to use as common a subset of command-line options and available information as possible. (You can generally find man pages for other *nix implementations online even if you don't have access to a system running that flavor of *nix. *smile*)
Also take the following command-line options:
-h or --help
Give a short help message explaining your purpose, command-line structure, and a description of each of these options.
-l or --long
List processes in long format. That is, give more information about the running process. This information should be a useful subset of that available from the standard ps command but arranged in a reader-friendly way. The path and/or command-line rather than just the command name, for instance.
It can also include information you can derive from that given by the ps command. For instance, how long the process has been running instead of just the start time (that way the user doesn't have to do mental calculations; *grin*).
-a or --all
Show processes for all users who currently have running processes.
This assignment is (Level 5).
Add (Level 2) to take care of removing users/processes dynamically as your program runs. That is, if user X was running process Y when your script began but process Y finishes before your report that would have contained Y comes out, remove Y from the report. And if that was X's last process, remove X from the report as well.
Also note that process Z from user W just started while you were gathering your --all list, so be sure to add this information to your report!
(Normal operation says that we don't care about stuff that happens in between when an action is requested and when we finish up the report. And there is only a certain amount of temporal accuracy we can guarantee, so don't sweat it too much. *smile*)
Add (Level 1) to add a -r or --raw option to just list the process ids (pids) of a user's processes. This would make your script useful for a pipe to the kill tool. If called with the executer as the user, list the pid of the script as well. (Useful for an admin, anyway. For a normal user it would pretty much be a sick way to log-out.)