Question

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

In UNIX

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

Using the commands who and cut, extract the list of usernames currently logged in the system

To check after a minute, the sleep command can be used: sleep 60

Get the new list of users logged in after a minute

For each user in the list;

check if he is 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

If the user is not in the second list, print that the user has logged out

For each user in the second list,

If he is in the first list, print that the user has logged in

Rename the second list as the first list

Repeat the process from step 2

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

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 seconds (10)

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

4 - save current "who" output into file "A" (overwrite)

5 - detect changes "diff" of files and output to console in formatted

6 - ctrl-c to 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
< b0user01 ttys010
< b0user02 ttys011

User(s) LoggedOut

> b93033 organ90

Waiting..

Add a comment
Know the answer?
Add Answer to:
In UNIX Write a script that checks each minute and reports on who logs in and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem 1 Write a BASH script to create a user account from the Linux system on...

    Problem 1 Write a BASH script to create a user account from the Linux system on which your script is run. The script should process two positional parameters. First positional parameter is supposed to be a string with a user name (e.g., user_name) Second positional parameter is supposed to be a string with a user password (e.g., user_password) In your script: Check if two positional parameters were passed to your script when it was invoked If NOT, print an appropriate...

  • I need this done ASAP. Please write a bash shell script that does the following: Prints...

    I need this done ASAP. Please write a bash shell script that does the following: Prints out how many users are logged on. This can be accomplished using who and wc. Prints out a list of currently logged on users. This can be accomplished using who, grep, regular expressions, and echo. Prints out how many processes you have running from past days, and a list of those jobs. Use `whoami` to get your username. Run ps -ef and see how...

  • Write a batch script, which combines a few tools in Linux to finish a big-data processing...

    Write a batch script, which combines a few tools in Linux to finish a big-data processing task --- finding out most frequently used words on Wikipedia pages. The execution of the script generates a list of distinct words used in the wikipedia pages and the number of occurrences of each word on these web pages. The words are sorted by the number of occurrences in ascending order. The following is a sample of output generated for 4 Wikipedia pages. 126...

  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

  • Exercise 1: Write a shell script that loops through the /etc/passwd file one line at a...

    Exercise 1: Write a shell script that loops through the /etc/passwd file one line at a time. Prepend each line with a line number followed by a colon and then a space. Example output: 1: root:x:0:0:root:/root:/bin/bash 2: daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin 3: bin:x:2:2:bin:/bin:/usr/sbin/nologin 4: sys:x:3:3:sys:/dev:/usr/sbin/nologin Exercise 2: Write a shell script that asks the user for the number of lines they would like to display from the /etc/passwd file and display those lines. Example output: How many lines of /etc/passwd would you like...

  • USING Unix/Linux shell !!!: 1) Write a script (project2.sh) that will take information from a file,...

    USING Unix/Linux shell !!!: 1) Write a script (project2.sh) that will take information from a file, and print (user’s choice of printers) identical form letters to each recipient. Either E197, E-199, E-194 printers or to project2.output. Prompt the user for their choice. 2) The script and output file are due: per Moodle timeline. Please upload your fully functioning script (project2.sh) your data file (project2.input) and your output file (project2.output) into Moodle. 3) Requirements of the script. a. You can use...

  • INFO 1211

    Lab 0: Essential UNIX OperationsObjectivesAt the end of this of lab, you should be able to:securely      log in to a remote computer running a UNIX-like operating systemread the      manual page for any commanduse the      UNIX file systemedit a      text fileNotes:·         In order to get familiar with UNIX, do all your work on UNIX.·         A command line interface may be harder to learn, but can be more powerful for scripting and automating tasks.·        ...

  • Please complete the following: Write a Python script to do the following: 1. Ask the use...

    Please complete the following: Write a Python script to do the following: 1. Ask the use to enter several sentences, one at a time in a loop). To end the sentence entry, the user enters a blank (empty) sentence. 2. Extract each word from each sentence and put it in a list. This will require at least one loop to go through each sentence in the list. It is up to you how you want to get the words in...

  • Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a....

    Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a. Write the following as script6.sh and change its permissions to count for num in d do if num eq 100 then count (count+1) done echo The number 10 was found $count times What is the output? Run the script as ./script6.sh 10 20 30 10 40 20 50 10 60 <enter Summarize what the script does r using the read command. The following script...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT