Sponsored Content
Top Forums Shell Programming and Scripting Bourne Shell script - log for users loggin on and off Post 302088028 by noodlesoup on Friday 8th of September 2006 05:27:45 AM
Old 09-08-2006
Bourne Shell script - log for users logging on and off

Hello all, I'm new to shell scripting and want to make a script that I can write to log the users logging on and off the a unix system.

I have had a good look over the past few days to crack it, I think I am getting close.

I want a script that runs an infinite loop to check every 5 seconds to report on who logs into and who logs out of the unix system.

This is a example of the output I would like:

PHP Code:
The current users are:
abc1
rv0
sxu
tgray

No user has logged in
/out in the last 5 seconds.

No user has logged in/out in the last 5 seconds.

User rsmith has logged in.

No user has logged in/out in the last 5 seconds.

User abc1 has logged out.

No user has logged in/out in the last 5 seconds
I am using
who | awk '{print $1}' | sort > temp1
to get the users logged on and saving that into a temp file.

and have a while loop set up like this which will run each 5 seconds.

while true
do
.
.
.
.
.
sleep 5
done

The problem I'm having is, I can't work out how to compare the current users logged in to the users that have previously logged in.

I thought of making a second temp file that stores the current users then using:
cmp temp1 temp2
to look at the difference. problem is it gives me an output saying "file differs at character 42, line 6" and that isn't helping me much as I would like to then display that users name but not sure how to print that position in the file (or just a line for that matter).

The test to see if the user has logged on or off is easy, as it is only a couple of if statements.

like if user is in temp1 but not in temp2 then the user has logged out and vice versa.

I have been looking at this for a while now and am going around in circles. any code fragments, help or written shell scripts Smilie would be greatly appreciated.

Thanks in advance

Noodle

Last edited by noodlesoup; 09-08-2006 at 06:34 AM..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
escape(1)                                                       Mail Avenger 0.8.3                                                       escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 04:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy