LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-07-2012, 09:43 AM   #1
AprendizZ
LQ Newbie
 
Registered: Mar 2012
Posts: 2

Rep: Reputation: Disabled
Unhappy Linux Shell Script Help! Add uptime logged users.


Hi!
Sorry if this is not the place to put my problem.
I'm newbie in Linux Shell Script and I need to create a special script.
From the var/log/wtmp file, I need to know, for each user, how many
times has she/he entered in the system and the total usage time.
If the user has not logged out, count the time until the present
moment.

I already do above:

First I maked a last -f /var/log/wtmp > teste.wtmp

The script:
#!/bin/bash
cut -c1-6 teste.wtmp |sort -buf > zteste.txt
cat zteste.txt
array=($(< zteste.txt))
for (( i = 0 ; i < ${#array[@]} ; i++ ))
do
echo ${array[$i]}
var=${array[$i]}
echo `grep -o $var teste.wtmp |wc -w`
done

But this only give me how many times has user entered.
Now I can't find a solution to add de times.
Any help?
Thanks.
 
Old 03-07-2012, 07:56 PM   #2
lisle2011
Member
 
Registered: Mar 2011
Location: Surrey B.C. Canada (Metro Vancouver)
Distribution: Slackware 2.6.33.4-smp
Posts: 183
Blog Entries: 1

Rep: Reputation: 25
Adding times

checkout ac 'man ac'

ac -d -y -p gives totals per user per day

since you already know how many times they went in and out should be an easy calculation
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script to add samba users dickohead Programming 14 11-18-2016 02:28 AM
[SOLVED] Script(s) to shutdown PC if no users logged in, ldap or TTY Linux.tar.gz Linux - Software 7 10-04-2010 04:17 AM
Shell script to store high water mark for uptime. McSlack Programming 5 10-18-2008 02:13 PM
Writing a script to kill users logged in twice scrizo Programming 7 10-10-2007 12:01 PM
Shell Script: Add Users from file flobadon Programming 3 12-07-2004 03:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration