shell to check user is logged on

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions shell to check user is logged on
# 1  
Old 04-05-2011
Question shell to check user is logged on

I was given this to do,

Write a Shell script to automatically check that a specified user is logged in to the computer.
The program should allow the person running the script to specify the name of the user to be checked, the frequency in seconds at which the script should check. If a checking frequency is not specified, it should default to 60 seconds
The script should check for the specified user and if found should output a message with a “beep” or “bell” sound to the screen stating that the user is logged in. It should also output a message to a log file stating that the user is logged in and specifying the date and time.
If the user is not logged in the script should output a message without any “beep” sound to the screen stating that the user is not logged in.
The script should allow a person running the script to specify the user name on the command line and optionally, a check frequency in seconds and a third argument “q” “q” . If “q” is present as a third argument, The script should omit any output to the screen or “beep” sound but should log to a log file the message stating that the user is logged in and giving the time.

The command to run the script would be as follows:
checklogin username 30 q where “checklogin” is the script name, “username” is the name of the user, “30” is the optional frequency to check in seconds, and “q” is the optional argument to suppress screen output.
The script should check that the number of arguments supplied is between 1 and 3 and if it is not, should terminate with an error message showing the correct syntax for the command.





so far iv done this
#get username
echo "enter username"
enter username
read username
who | grep $username
#while exit status is false continue to check
while [ $? !=0 ]
do
sleep 60
done




Any help you can give finishing this would be greatly appreciated
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. Programming

Check if user logged into remote machine via C++ / Java

Hi, I have a program running on HP-UX and it must checkwhether a user has already logged-in to another machine. The hostname of the other machine is known when the check has to be made. Is there a way which this can be accomplished using C++ or Java? If not I could parse the output of a... (6 Replies)
Discussion started by: johnmmcparland
6 Replies

8. Shell Programming and Scripting

Check if user exists shell

Hello! I'm stuck with a problem that i can't solve. I'm very new to unix, linux and shell scripting i might add. I'm trying to create a script that will execute as follows: First start the script - sh exist Then the prompt asks the user to input a username to check if it exists within the... (6 Replies)
Discussion started by: bib2006
6 Replies

9. Shell Programming and Scripting

Script to check users logged out

Hi, Here is the script that I have written to check if a particular user is has logged out, and if yes, then a mail needs to be sent to the management the details of whatever has been captured by the script command. echo "The current users are:" who | awk '{print $1}' | sort > temp1 cp... (1 Reply)
Discussion started by: ggayathri
1 Replies

10. 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
Login or Register to Ask a Question