Solved

shell program

Posted on 2000-04-23
6
312 Views
Last Modified: 2010-04-21
write a shell program(boune shell) on the following topic.

watching all people logging in and out and report as people come and go- a sort of incremental who. also display statistics of people logged in and logged out every 2 minutes.
0
Comment
Question by:sriram_bandi
6 Comments
 
LVL 2

Expert Comment

by:festive
ID: 2742966
well you could do the following:
tail -f /var/log/syslog

this will give you a complete running log and some other usefull info.

alternatively:

#!/bin/sh -p
while true; do
    who
    sleep 120
done >> /usr/local/logs/userlog.log
0
 

Author Comment

by:sriram_bandi
ID: 2746019
it's not a incremental who
0
 

Accepted Solution

by:
etdey earned 50 total points
ID: 2746288
#!/bin/sh
#
# watch_logins.sh
#

last | grep -v "still logged in" > /tmp/last.off.log0
last | grep    "still logged in" > /tmp/last.on.log0

echo "First cycle is empty..."

while [ 1 ]; do

  last | grep -v "still logged in" > /tmp/last.off.log1
  last | grep    "still logged in" > /tmp/last.on.log1

  echo "-----------------------------"
  date
  echo "-----------------------------"

  echo "Logins:"
  echo "-------"
  diff /tmp/last.on.log0  /tmp/last.on.log1 | egrep '^> '

  echo ""

  echo "Logoffs:"
  echo "--------"
  diff /tmp/last.off.log0  /tmp/last.off.log1 | egrep '^> '

  echo ""

  mv /tmp/last.off.log1 /tmp/last.off.log0
  mv /tmp/last.on.log1 /tmp/last.on.log0

  sleep 120

done
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 20

Expert Comment

by:tfewster
ID: 2747933
This guy seems a bit smarter than the last person who asked for the answers on this homework assignment a couple of months ago:
- He's split the paper into 2 questions, rather than ask them all together
- He's not asked the "Test if a string is a palindrome" question, so I guess he's worked it out himself ;-)

0
 
LVL 2

Expert Comment

by:festive
ID: 2750848
agreed, interesting comment , first he says that he wants "a sort of incremental who", then he rejects two ways of achieving it, admittedly the who was cheap and nasty, But so is someone cheating on their homework. :-)
0
 
LVL 20

Expert Comment

by:tfewster
ID: 2759881
I see the palindrome question HAS been posted now :-)

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question