script on user who logged in????


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script on user who logged in????
# 1  
Old 04-30-2008
script on user who logged in????

writing a script that will check every 5 seconds whether a particular user has
logged into the system

Code:
# Determine if someone is logged on
# Version 4.0
if [ “$#” ne
1 ]
then
echo “ Incorrect number of arguments”
echo “Usage: $ ison4 <user>”
else
user=“$1”
if who | grep “$user” > /dev/null
then
echo “$user is logged on”
else
echo “$user is not logged on”
fi
fi

is this ok

Last edited by Yogesh Sawant; 04-30-2008 at 06:27 AM.. Reason: added code tags
# 2  
Old 04-30-2008
I don't see the loop and the "sleep 5" but as the body of that missing loop, this looks okay (though mind-numbingly verbose -- I guess you want to take out the "is not" case once you have made sure it works correctly).
# 3  
Old 04-30-2008
how about converting this:
Code:
echo “Usage: $ ison4 <user>”

to:
Code:
echo “Usage: $0 username”

are you planning to run this script using watch ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

• Write a shell script that upon invocation shows the time and date and lists all the logged-in user

help me (1 Reply)
Discussion started by: sonu pandey
1 Replies

2. Red Hat

How to confirm an user logged in is a remote user?

How do I confirm if a user logged in, is remote or local? In the case if the user is remote, how to be sure what authentication/method is it using, like LDAP, NIS or other? (2 Replies)
Discussion started by: kirtikjr
2 Replies

3. Shell Programming and Scripting

Does running a cron job of a user require the user to be logged in?

Suppose user 'asdf' is not logged into server 'bbbb', but the server is up. User 'asdf' has cron job. Will it be executed? (1 Reply)
Discussion started by: thulasidharan2k
1 Replies

4. Shell Programming and Scripting

HOW: Shell script accessing files located in individual logged in user.

Hi I have below scenario, I hope this could be possible, but as of now no idea how to implement this. Mount point in this location /abc/mp, and there will different users who will be executing one the file shell1.sh file located in /abs/mp, but every user will execute this shell1.sh file from... (1 Reply)
Discussion started by: shekharjchandra
1 Replies

5. Shell Programming and Scripting

Shell script to display user logged last week and time connected

Hello all, I want to display all the user logged last week and know the time tnat they are connected. I have been looking for a solution in the Forum, but I didn't find. Thanks in advance (4 Replies)
Discussion started by: ahernandez
4 Replies

6. UNIX Desktop Questions & Answers

Shell script to display user logged in within given time

how can i know which users have logged in at specified given start and end time in 24 hour format? (3 Replies)
Discussion started by: meherzad4u
3 Replies

7. Shell Programming and Scripting

Get current logged in user from a script run as root.

Ok, so, in order to install some dependencies of a program I made, a script has to be run as root. The thing is that I have to copy some things into the home folder of currently logged in user, but the variable $HOME returns '/root' and the $USER returns 'root' :( Is there any way to see who is... (7 Replies)
Discussion started by: hakermania
7 Replies

8. UNIX for Advanced & Expert Users

Send email as a different user than the user logged in

Hi I am using mailx to send email and am wondering if there is a way I can send the email from a different user than the user logged in. something like do-not-reply@xyz.com Thank you. (1 Reply)
Discussion started by: rakeshou
1 Replies

9. Shell Programming and Scripting

user logged on?

Hi, What commands do i need to check if a user is logged on to the network? thanks. (1 Reply)
Discussion started by: provo
1 Replies

10. UNIX for Dummies Questions & Answers

Is user logged on??

How can i check to see if a user is logged on to the network? (1 Reply)
Discussion started by: provo
1 Replies
Login or Register to Ask a Question