Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

shell program

Posted on 2000-04-23
4
333 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
  • 3
4 Comments
 
LVL 2

Expert Comment

by:jonke
ID: 2744204
Is this the sort of thing you are after?

#!/bin/ksh
#
#Lets see who is on the system at the moment
#
clear
echo "USERS WHO ARE CURRENTLY ON THE SYSTEM"
echo ""
who
who > /tmp/who1
#
#Create an eternal loop
#
LOOP=1
while (( $LOOP == 1 ))
        do
        sleep 20
#
#Make it all nice and neat
#
        clear
        echo "USERS WHO ARE CURRENTLY ON THE SYSTEM"
        echo ""
        who
        who > /tmp/who2
#
#Compare who output, with the one from 2 mins ago
#
        diff /tmp/who1 /tmp/who2 > /tmp/who_diff
        grep ">" /tmp/who_diff > /tmp/who_joined
        grep "<" /tmp/who_diff > /tmp/who_left
#
#Then output who is currently on the system, who has left and who has joined
#in a presentable format
#
        echo ""
        echo "USERS THAT HAVE LOGGED ONTO THE SYSTEM"
        echo ""
                if [[ -s /tmp/who_joined ]]
                then
                cat /tmp/who_joined
                else
                echo "No users have logged onto the system in the last 2 mins"
                fi
0
 
LVL 2

Expert Comment

by:jonke
ID: 2744243
Sorry- you wanted bourne shell didn't you?

Here is the revised version:

#!/bin/sh
#
#Lets see who is on the system st the moment
#
clear
echo "USERS WHO ARE CURRENTLY ON THE SYSTEM"
echo ""
who
who > /tmp/who1
#
#Create an eternal loop
#
while [ 1 ]
        do
        sleep 120
#
#Make it all nice and neat
#
        clear
        echo "USERS WHO ARE CURRENTLY ON THE SYSTEM"
        echo ""
        who
        who > /tmp/who2
#
#Compare who output, with the one from 2 mins ago
#
        diff /tmp/who1 /tmp/who2 > /tmp/who_diff
        grep ">" /tmp/who_diff > /tmp/who_joined
        grep "<" /tmp/who_diff > /tmp/who_left
#
#Then output who is currently on the system, who has left and who has joined
#in a presentable format
#
        echo ""
        echo "USERS THAT HAVE LOGGED ONTO THE SYSTEM"
        echo ""
                if [ -s /tmp/who_joined ]
                then
                cat /tmp/who_joined
                else
                echo "No users have logged onto the system in the last 2 mins"
                fi
        echo ""
        echo "USERS THAT HAVE LEFT THE SYSTEM"
        echo ""
                if [ -s /tmp/who_left ]

then
                cat /tmp/who_left
                else
                echo "No users have logged off the system in the last 2 mins"
                fi
        echo ""
        cp /tmp/who2 /tmp/who1
        rm /tmp/who_joined /tmp/who_left
done
0
 
LVL 2

Accepted Solution

by:
jonke earned 50 total points
ID: 2746515
Is the above ok?
0
 

Author Comment

by:sriram_bandi
ID: 2750742
Thanks a lot jonke... I executed the program it is working good.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

766 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