Solved

shell program

Posted on 2000-04-23
4
320 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
Comment Utility
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
Comment Utility
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
Comment Utility
Is the above ok?
0
 

Author Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded‚Ķ
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now