Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

shell program

Posted on 2000-04-23
4
Medium Priority
?
357 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
[X]
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
  • 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 150 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

Hire Technology Freelancers with Gigs

Work with 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

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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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.

650 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