BEST代写-线上留学生作业代写 & 论文代写专家

成立于2015年的老牌留学生代写品牌-BEST代写提供超过百门冷热门留学学科的作业和论文代写服务。全网BEST原创,高质,准时的留学生代写。

操作系统代写 | KIT501 UNIX Scripting Assignment

操作系统代写 | KIT501 UNIX Scripting Assignment

本次澳洲代写是Unix Shell脚本的一个assignment

Task B

Write a shell script (to run on the Bourne shell) that uses an infinite loop (i.e. it runs forever unless interrupted by the control-c key sequence) to check every 3 seconds to report on who logs into and who logs out of a UNIX system. To simplify the script, you can ignore multiple logins from the same user during a time period of less than 3 seconds, or cases where a user logs in and logs out during the same 3 second time period.

Specific Task B Requirements

  1. Your script for this task must be named sh
  1. Make sure your script is user-friendly and follows common sense – your script should use consistent indentation and include whitespace/blank lines (where relevant) to make the script more logical and easier for a person to read. You must also include general inline comments in the script code to indicate the purpose of more complex command combinations
  2. Your script must include comments at the start to specify:
    1. the script’s purpose,
    2. the author (including student number),
    3. and the date (when last modified).
  1. When the script starts executing, it must display the following:

The current time is:

followed by (on the next line) the current date and time e.g.

Wed Sep 1 13:18:32 AEST 2021

  1. The script must then display a sorted list of usernames of users who are currently logged in:

(using example usernames)

The current users are:

dherbert jsmithe sxu

  1. Then, every three seconds, the script must display a list of users who have logged in, followed by a list of users who have logged out: (using example usernames)

User abcd has logged in. User jsmith has logged in.

User dherbert has logged out. User jsmithe has logged out.

Continued on next page…

If no user logged in or out during a three second period, then the following message should be displayed:

No user has logged in/out in the last 3 seconds.

Task B Example output

The following is a sample output of the script (It is OK if the script leaves behind a temporary file when it is finally interrupted). The $ is the shell prompt.

Task B Extra Hints:

  • Work out how to determine who is logged in – you only want the username part of the output
  • Remember the list of users you’ve found above to a file (imagine this is the first list)
  • Create a loop that will run every 3 seconds
  • Within the loop, determine again who is logged in (saving the username results to another file – imagine this is the second list). Compare this list of usernames with the first list you saved before. Differences between the files indicate usernames who have logged in or out – for each file you may have to use another loop to go through each username in turn in order to determine if it’s present (or not) in the other For example, if a user “bob” is in the first list of usernames but not the second list of usernames, then bob has logged out. If bob is in the second list but not the first list, then bob has logged in. If both lists are exactly the same, then no-one has logged in or out.
  • Each iteration of your loop, the second list of usernames from before should become the first list of usernames (they are now old, from 3 seconds in the past) so you can then compare it with a (new) second list of usernames that have just been
  • Some users might be logged in multiple times at once, so when you generate a list of who’s logged in, your list should be sorted and only contain unique usernames…
bestdaixie

评论已关闭。