Help script for login times


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help script for login times
# 1  
Old 10-05-2006
Data Help script for login times

I am new to shellscript . PLease help me how can I write the following script.


[ ray@linux ] $ who
ray pts/0 aug 31 01:18 ( 65.169.28.200 )
ray pts/1 sep 2 02:28 ( 65.169.28.200 )
bob pts/3 sep 2 02:31 ( 65.169.28.201 )

when run the command who |./ script , the script should print out how many times users are logged in and listing all the user's login times in the same line.

example output: 2 ray aug-31-01:18 sep-2-02:28
1 bob sep-2-02:31
# 2  
Old 10-05-2006
This seems to work:

Code:
#!/bin/bash -  

if [ $# -lt 1 ]; then   
  echo "Usage: `basename $0` <user>"   
  exit 
fi  

USER=$1 
LOGINS=`who | grep $USER | wc -l` 
TIMES=`who | awk '{print $3,$4,$5}' | sed -e 's/\n/ /g' -e 's/ /-/g'`

echo "$LOGINS $USER $TIMES"


Last edited by petebear; 10-05-2006 at 10:33 PM..
# 3  
Old 10-06-2006
thanks

Thanks for the help
# 4  
Old 10-06-2006
You're welcome.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Schedule script is not executing some times

Dear Experts, Once again i need your vital help to fix my issue, please do the needfull. Issue:- I have schedule one script on windows server to run's every 10 min.(Script do check the alert log file,if database found down it send the email) While i'm doing the database down manually its... (12 Replies)
Discussion started by: Mohammed Fareed
12 Replies

2. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

3. Shell Programming and Scripting

Counting script how many times it run?

i should use this script runs how many times before ? how can i do_? (3 Replies)
Discussion started by: utoptas
3 Replies

4. Shell Programming and Scripting

Shell script to run x times

Hi, First i need to cd to this directory $SWDIR/util Second i need to run the following either 4 times or 20 times ./swadm add_process 1 BG Y how can i put this in a script which should ask for user input on how many times you want to run this Thanks, (5 Replies)
Discussion started by: lookinginfo
5 Replies

5. Shell Programming and Scripting

script for comparing the times.

Hi, My below output file looks like this. Backup status at Tue Jul 7 03:30:07 EDT 2009 CMLP Job Name Last Start Last End ST Run Pri/Xit ____________________________ ____________________ ____________________ __ _______ ___ tnx415uu 07/06/2009 22:01:41 ----- RU 5547800/1 tnp415uu 07/06/2009... (2 Replies)
Discussion started by: intiraju
2 Replies

6. AIX

how would you know your server was rebooted 3 times or 5 times

Is there such location or command to know how many times did you reboot your server in that particular day?in AIX. (3 Replies)
Discussion started by: kenshinhimura
3 Replies

7. BSD

Deny logon for x hours if login failed x times

Hello, I have a small inquiry. Sometimes, my good friend, Charlie Root, sends me security notifications that a possible breakin attempt has occured. It looks like this: Oct 29 06:58:17 cigva sshd: reverse mapping checking getaddrinfo for 180.144.164.220.broad.sm.yn.dynamic.163data.com.cn ... (2 Replies)
Discussion started by: brightstorm
2 Replies

8. Shell Programming and Scripting

Awk script to add times.

Hey, Im trying to format the last command to tell me just the user names, logins, and the time that they were logged in. So far I got the users logins using a loop that counts the amount of times a user logged in but im not sure how to start the time array. The time im trying to use is the last... (2 Replies)
Discussion started by: Trilogie
2 Replies

9. AIX

Number of login times

Hi! I'm currently using AIX 4.3 and would like to know where can i find to see that there's a restriction on the number of login times a user can have. Example, I want to see whether user A has only 1 login while user B can have 2 logins (without logging off the first one). Would I be able to... (7 Replies)
Discussion started by: ftengcheng
7 Replies

10. UNIX for Dummies Questions & Answers

How to block the IP after many times fail login?

Hi, there. I am using Red Hat 9 to run my web server. Recently I found lots tempts from different IP addresses tried to login into my system. I am not sure if they are the same person or not. Since this server is only for web hosting purpose for couple of my friends and myself, so it is very easy... (2 Replies)
Discussion started by: HOUSCOUS
2 Replies
Login or Register to Ask a Question