Solved

shell program

Posted on 2000-04-23
4
328 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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.:
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…

803 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