Track user log!

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Track user log!
# 1  
Old 05-27-2010
Error Track user log!

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
The task is to measure the density of users that are logged on system. The program
should check that every 30 sec, but not check older logs than 2 days(24h) and write that into a text file. So the logs shouldn't be older than 2 days. The records of logged users must be saved in a file for today and what was going on yesterday.
And the time difference MUST be 30 seconds between checkings...

It should look like this:
Time: 11:50:10 Users: 2
Time: 11:50:40 Users: 5

1.file for today Today.txt
2.file for yesterday logs Yesterday.txt

2. Relevant commands, code, scripts, algorithms:
??


3. The attempts at a solution (include all code and scripts):
I'm thinking about the function who -Hlrmu and to cat that into a file
than read how many lines a file has minus the first one.

Code:
#!/bin/bash

while true; do
sleep 30
users=$(who -Hlrmu | cat >> record.txt | wc -l record.txt | cut -c1-2)
echo -e "Time: ???? Users:$users\n"

done
exit


I don't know how to measure the time and to separate the files into two,
one for today and one for yesterday.

Am I on the right path? I'm not i know hahaha

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
University of Ljubljana, Ljubljana, Slovenia, Janez Novak, ID63709


Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by radoulov; 05-27-2010 at 06:59 PM.. Reason: changed title; deleted "urgent"
# 2  
Old 05-27-2010
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.


Thank you.

The UNIX and Linux Forums
# 3  
Old 05-27-2010
Hmm but i must post a homework in a correct forum, and my homework is in a rush, so
i still can post a homework in the Emergency UNIX and Linux Support !! Help Me!! - The UNIX and Linux Forums ???
# 4  
Old 05-27-2010
just read the rules and don't use words like "urgent" in your title.
# 5  
Old 05-28-2010
Ok i will, can you help me with the problem i have?

---------- Post updated 28-05-10 at 02:03 PM ---------- Previous update was 27-05-10 at 08:18 PM ----------

Does the who -m lists users who are on the system or just me?

would it be better if i used the command users or simply who ?
# 6  
Old 05-28-2010
You can use who to get the number of users logged in your system...

who -m will show you "only hostname and user associated with stdin"

Code:
man who

Try this:

Quote:
echo "Time: $(date +%T) Users: $(who | wc -l)" >> $(date +%Y%m%d).log
You'll need to adjust the output redirection and maybe the cron schedule.
# 7  
Old 05-28-2010
Aha, what if i use $(users | wc -l)
coz, who returns me on two consoles tty7 and pts/0

How can i separate the files, the Today.txt must contain users who were logged in today
and Yesterday.txt must contain yesterday logs, and i should have no more than 2 days old logs.

Something like if [ $(date +%Y%m%d).log -ge than 48h ]; than delete it?
How can i tell if a file is older than 2 days?

---------- Post updated at 03:58 PM ---------- Previous update was at 02:40 PM ----------

it would be even better if i rewrite from today.txt into yesterday.txt, but only when
24 hours passes and the today.txt will be blank.
What i mean is...i must keep track of the users for 24 h and then rewrite it
to a yesterday.txt file!Smilie

How is that doable???

Last edited by petel1; 05-28-2010 at 02:07 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Track activity of a user

Hi All We have a job which writes files to a server at a particular time. The files will be created by a particular user ID Today, during the execution of the job, it created a file to the server and the file sat on the server for sometime, but was deleted immediately at the end of the... (4 Replies)
Discussion started by: sparks
4 Replies

2. UNIX for Dummies Questions & Answers

How to track user activity?

Hi All Please can you help me with the following issue: A certain vendor installed an application in which for a user to log in; the user must use a user created/predefined by the application. And because this application has more than one user its difficult to track who did what and when,... (6 Replies)
Discussion started by: fretagi
6 Replies

3. UNIX for Dummies Questions & Answers

Track user

Hi, i suddenly realized that a directory is deleted unfortunately there are many user have pervilages on this directory is there a way to track the user who delete this directory or atleast from now can i enable something so that i can track from now I think there is way from... (2 Replies)
Discussion started by: crackgeek
2 Replies

4. AIX

Track deleted OS user accounts

Recently we've had a couple user accounts mysteriously disappear. Is there any way to track these accounts and determine who/how they were deleted? (2 Replies)
Discussion started by: Sk0glund
2 Replies

5. UNIX for Advanced & Expert Users

Track user commands

Hi, I have a unix server and I am concerned about the security on that server. I would like to be able to write a script that records all the commands that were typed at the command prompt before the user calls the 'history -c' command and deletes all the history. I was thinking about firing or... (7 Replies)
Discussion started by: mishkamima
7 Replies

6. AIX

Track user logoff in AIX 5.3

Hi Does anybody know if there is a way in AIX 5.3 to track how a user was logged off? For instance where the user typed exit, hit crtl D, shell process was killed, etc. I know of the last log entries but this just shows a users login time and duration. I also tried syslog but I only get login... (5 Replies)
Discussion started by: kimyo
5 Replies

7. Shell Programming and Scripting

keep track of every user

dear all , I m new to shell programming and I need your help. Actually i want to keep track of all the commands executed in a bash prompt of users , very much in same manner as it is displayed when we run "history" command. now the users are smart enough as they delete their history by... (6 Replies)
Discussion started by: xander
6 Replies

8. UNIX for Dummies Questions & Answers

Possible to track FTP user last login? Last and Finger don't track them.

Like the topic says, does anyone know if it is possible to check to see when an FTP only user has logged in? Because the shell is /bin/false and they are only using FTP to access the system doing a "finger" or "last" it says they have never logged in. Is there a way to see when ftp users log in... (1 Reply)
Discussion started by: LordJezo
1 Replies

9. UNIX for Advanced & Expert Users

Track user activity --pls help

hi I want to know how to save all the command used by all the used under a particular root with the time stamp in a file. Eg: User Name: UX10 Time: 10:56 Command: LS User Name: UX23 Time: 10:59 Command: MORE abc.txt -Anand (2 Replies)
Discussion started by: anandtharani
2 Replies

10. Programming

keep track of the last 10 commands the user typed

Can I do it like this? if (strcmp(argv, "history")==0) { argv = "10"; execvp(argc,argv); } actually, it doesn't work, How can I modify it? Thanks (17 Replies)
Discussion started by: zhshqzyc
17 Replies
Login or Register to Ask a Question