Question

In: Computer Science

Write a script that checks each minute and reports on who logs in and who logs...

Write a script that checks each minute and reports on who logs in and who logs out.

You can follow the steps below (not the only way):

  1. Using the commands who and cut, extract the list of usernames currently logged in the system
  2. To check after a minute, the sleep command can be used: sleep 60
  3. Get the new list of users logged in after a minute
  4. For each user in the list;
    1. check if they are in the second list using if and grep. You can dump the output of grep to /dev/null when using it in the as a test for the if statement
    2. If the user is not in the second list, print that the user has logged out
  5. For each user in the second list,
    1. If he is in the first list, print that the user has logged in
  6. Rename the second list as the first list
  7. Repeat the process from step 2

Solutions

Expert Solution

1). ANSWER :

GIVENTHAT :

Write a script that checks each minute and reports on who logs in and who logs out.

Below is algo used for bash script :-

steps :

0. Infinite while loop :

1. save current "who"output into a file "A"

2. wait for configured scconds(10)

3. move file "A" to "B"(new file)

4. saw current "who" output into file "A"(overwrite)

5. detect change "diff" of files and output to console in formatted

6. ctrl-c quit

code :-

fileOne ="/tmp/a.md"

fileTwo="/tmp/b.md"

clear

while true;do

echo"\n\tWaiting..\n"

for i in $(seq 1 10);

do

# echo $i

sleep 1

done

echo "Diff..\n"

mv $fileOne $fileTwo

who >$fileOne

echo "User(s) LoggedIn"

diff $fileOne $fileTwo | grep "<" | cut-d ' ' -f

1,2,3

echo "\nUser(s) LoggedOut"

diff $fileOne $fileTwo | grep ">" | cut-d ' ' -f

1,2,3

sleep 1

who > $fileOne

done

Sample Output :-

Waiting..

Diff..

User(s) LoggedIn

<b0users01ttys010

<b0user02 ttys011

User(s) LoggedOut

>b93033 organ90


Related Solutions

write a 2-minute sales Elevator Pitch script for an EXISTING product of your choice. Use 5...
write a 2-minute sales Elevator Pitch script for an EXISTING product of your choice. Use 5 real Statistics to back up your case. Research them and make sure they are real statistics.
1. Employee A receives checks from customers and logs them into the register for check receipts...
1. Employee A receives checks from customers and logs them into the register for check receipts (sub-ledger). S/he also posts the receipt to the relevant customer sub-ledger and is responsible for depositing the checks into bank. (Amounts from sub-ledgers are posted into the General ledger). However, in the most recent month, the employee deposited receipts from 3 customers in a personal bank account that s/he opened in a name similar to that of the Company. Which of the following control(s),...
Recent crime reports indicate that, on average, 3.1 motor vehicle thefts occur each minute in the...
Recent crime reports indicate that, on average, 3.1 motor vehicle thefts occur each minute in the United States. What is the probability there are no thefts in a minute? You should use the finite population correction factor for this problem. True False
A table factory requires 500 logs per year. Each time an order for logs is placed,...
A table factory requires 500 logs per year. Each time an order for logs is placed, an ordering cost of $20 is incurred. Each log costs $12 and the holding cost is $2/log/year. Assume that demand occurs at a constant rate and shortages are not allowed and the lead time is zero. (a) If the quantity ordered is 150 units, calculate the total cost incurred (including ordering costs, purchasing costs and holding costs). (b) What is EOQ? (c) What is...
Assess the following argument by analogy: Go through each of the 3 checks, and then write...
Assess the following argument by analogy: Go through each of the 3 checks, and then write your conclusion about the analogy (strong or weak). Check #1: Specify exactly what is being compared Check #2: List several similarities (both of the objects/events/ideas compared have a, b, and c). Check #3: Find at least 1 key difference if you can (the objects/events/ideas compared are different in d or in e). This is a matter of quality, not quantity Is this weak or...
Write a program that checks if all the input numbers cover 1 to 99. Each ticket...
Write a program that checks if all the input numbers cover 1 to 99. Each ticket for the Pick-10 lotto has 10 unique numbers ranging from 1 to 99. Suppose you buy a lot of tickets and like to have them cover all numbers from 1 to 99. Write a program that reads the ticket numbers from a file and checks whether all numbers are covered. Assume the last ending number in the file is 0. Suppose the file contains...
Write a complete shell script that first asks the user to enter a URL. The script...
Write a complete shell script that first asks the user to enter a URL. The script should read the URL into a variable named url. The shell script should then retrieve the file associated with the URL by using the curl command. The output of the curl command should be redirected to a file named html_file. The shell script should then use the grep command to search the file named html_file for the word manhattan. Finally, the shell script should...
Fully Functional Script written in BASH In this section, you will write a fully functional script...
Fully Functional Script written in BASH In this section, you will write a fully functional script to help your manager with an important project that will build upon what you learned from your script work in Milestone Four. After you have written the script, you will execute it to generate a report for all three users (once for Bob, once for Henry, and once for Frank). You should have three unique generated reports in your ~/scripts directory (or more if...
Write Powershell Script Verifies System Environment Variable Lmlicensefile Exists Exists S Q42980878 write a PowerShell script...
Write Powershell Script Verifies System Environment Variable Lmlicensefile Exists Exists S Q42980878 write a PowerShell script that verifies the 'System' environmentvariable, 'LM_LICENSE_FILE', exists. If it exists, the scriptshould also verify that the variable [email protected] (which represents the port and server theLM points to) as one of the values in the variable. Values (if anyare present) are separated by commas "," in this variable. Finally,if the value does not exist, this script should also performremediation (add the desired value to the...
USING MATLAB write a script that creates eight subplots(4x2). In each one, graph the values of...
USING MATLAB write a script that creates eight subplots(4x2). In each one, graph the values of sin(n(pi)x), where -1 <=x<=1, with an interval of 0.05 for n = 1 to 8. there is no parenthesis on pi. I just didn't want to make it look like (npix) so it wouldn't be confusing to read.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT