Bourne Shell script - log for users loggin on and off


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bourne Shell script - log for users loggin on and off
# 8  
Old 09-08-2006
Code:
        if [ $file = "temp1" ]; then
            echo "User "$user" has logged out."
        fi
            
        
        if [ $file = "temp2" ]; then
            echo "User "$user" has logged in." 
        fi

# 9  
Old 09-08-2006
solution::try this code
Code:
#! /bin/sh 

echo "The current users are:" 

who | awk '{print $1}' | sort > temp1 
cp temp1 temp2 
more temp1 

while true 
do 
    who | awk '{print $1}' | sort > temp2 
    cmp -s temp1 temp2 

    case "$?" in 
     
    0) 
        echo "No user has logged in/out in the last 5 seconds." 
        ;; 
     
    1) 
        user=`comm -23 temp1 temp2` 
        file=`grep $user temp1 temp2 | cut -c 1-5` 

        [ $file = "temp1" ] && echo "User "$user" has logged out." 
             
         
        [ $file = "temp2" ] && echo "User "$user" has logged in." 
        ;; 
         
    esac 
    rm temp1 
    mv temp2 temp1 
    sleep 5 

done

# 10  
Old 09-08-2006
If you have unix accounting turned on you can use the last command. The history for user logins would stay until you roll the file. We accumulate the history by day per user then roll the log to start over.

user1 pts/6 mypc1 Fri Sep 8 08:15 still logged in
user2 ftp mypc2 Fri Sep 8 08:05 - 08:05 (00:00)
# 11  
Old 09-08-2006
thanks heaps for the help guys. works just how I wanted Smilie
# 12  
Old 09-08-2006
Here is the Out put of the Code for #9 when you login from other terminal it throw error similarly at the time of logout ???

$ ./u1.sh
The current users are:
coetest1
coetest1
root
root
root
root
root
root
root
No user has logged in/out in the last 5 seconds.
No user has logged in/out in the last 5 seconds.
No user has logged in/out in the last 5 seconds.
./u1.sh[22]: temp1: unknown test operator
./u1.sh[25]: temp1: unknown test operator
No user has logged in/out in the last 5 seconds.
No user has logged in/out in the last 5 seconds.


what do you mean by unknown test operator ??
# 13  
Old 09-08-2006
I guess instead of user=`comm -23 temp1 temp2`
it should be user=`comm -13 temp1 temp2` ### 23 should be 13 ??

check my suggestion
# 14  
Old 09-08-2006
yeah I'm getting the same error now. it doesn't work with the -13 option in comm either. any suggestions?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

New user needs help with bourne shell script

This is my question, below the question is the template Write and execute a Bourne shell script called homework that will From within the script, create three background processes: a) (2 points) one that saves a long listing of your hidden files to a file named hiddenlist b) (2 points) ... (4 Replies)
Discussion started by: luislozoya
4 Replies

2. Shell Programming and Scripting

Shell Script to zip users cmd history log files

I admit I am terrible with scripting, so when I was asked to store users' command history lines and zip them on monthly basis what I did was to create a file "user_history_Feb" with the following contents: Part A # more user_history_Feb cp -p /var/log/user_history/*history... (6 Replies)
Discussion started by: hedkandi
6 Replies

3. Red Hat

Loggin SFTP activity for chrooted (rssh) users

Hi, I need to log the activity of my SFTP (RHEL 5.4). I have this in /etc/sshd/sshd_config: Subsystem sftp /usr/libexec/openssh/sftp-server -f LOCAL5 -l VERBOSE And this in /etc/syslog.conf: LOCAL5.* /var/log/sftp.log When I log in... (1 Reply)
Discussion started by: Tr0cken
1 Replies

4. Shell Programming and Scripting

help with bourne shell script

Attempting to write a script to eventually notify me via email for when there is packetloss across the backbone. I am looking for values greater than 0% in the mtr field. #!/bin/sh target=www.google.com date +"%D"_"%T" >> /home/rich/mtr.log echo "----------------------------------------" >>... (1 Reply)
Discussion started by: closedown
1 Replies

5. Shell Programming and Scripting

loggin in using different user from with in the shell script

Hi, I want to login using different login credentials from with in the shell script. I need to do this so that I can run a second script which can be run using only by that user. eg. #!/bin/bash #login using new user username: password: sh script.bash #logout above... (2 Replies)
Discussion started by: shishirkotkar
2 Replies

6. Shell Programming and Scripting

how to log if the program contains both bourne-shell & pearl scripts

I have a program (say, MyProgram) written in Bourne-shell script, but at some point it calls another script written in pearl, as illustrated below: #!/bin/sh ..... case $x in 1) ConfigSystem1 ( b-shell script) 2) ConfigSystem2 ( pl) 3) ConfigSystem3 (b-shell) .... Then I create... (0 Replies)
Discussion started by: bluemoon1
0 Replies

7. Shell Programming and Scripting

cd from a Bourne Shell Script - Please Help

Dear Bourne Shell Expert, I am trying to change the current working directory from within a Bourne Shell script. Simply enough i thought ! As I am sure you are well aware, Inside the script i echo `pwd` and it seems ok, but the shell spawns another shell to execute this and as such, when my... (10 Replies)
Discussion started by: fawqati
10 Replies

8. UNIX for Dummies Questions & Answers

Bourne Shell Script

Hello, I'm throwing this out there as a novice to the Unix world...I've been working on a project that requires me to ouput (using the echo command) a list of names in a single column format, but the problem is the input is in row format followed by a blank space...If anyone could give me a... (2 Replies)
Discussion started by: dmhonor914
2 Replies

9. Shell Programming and Scripting

bourne shell script

Hi all, Can somebody answer the following query Thanks, Srinivas A shell program that takes one or any number of file directory names as input; sorts the directories given as parameters jointly in the ascending or decending order of choice For EX : dips abc etc desc will sort the files... (2 Replies)
Discussion started by: psrinivas
2 Replies

10. UNIX for Advanced & Expert Users

Bourne shell script need help please ?

i have this assignment.. and i mad this script but there is something wrong with it.. if anyone can tell me.. watz going on... i would appreciate it.. tHnX in advance.. count=1 val=$2 op=$1 ans=0 if then if then while do ... (7 Replies)
Discussion started by: dezithug
7 Replies
Login or Register to Ask a Question