LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-06-2012, 10:35 PM   #1
LBP74
LQ Newbie
 
Registered: Nov 2012
Posts: 4

Rep: Reputation: Disabled
Question Looking for command to help with program


I need to be able to calculate the amount of time a user has been logged onto the system for.

UsrMin=$(who | grep $1 | cut -c30-35)
Time=$(date +%H:%M)
echo $UsrMin
echo $Time
echo LoginTime CurrentTime
echo ' '$UsrMin - $Time
~

conntime f132a13
20:57
21:18
LoginTime CurrentTime
20:57 - 21:18


This is as close as I could get to figuring out my problem. It wouldn't allow me to do the subtraction so I left it like this. Please help!
 
Old 12-06-2012, 11:13 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Extending that method, you'd convert the hrs to mins, add the extra mins, then subtract 'now' from 'then', optionally converting the result to hrs and mins if diff_result > 60.
Of course, this only works when the login time is in the same day as the current time. For a more general approach, you'd have to calc the date diff as well, probably using the various date format options.

Personally, if this was for a serious eg prod system, I'd likely do it in Perl as it has plenty of date calc routines.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Last installed program command Dhanasekaran R Linux - Newbie 1 08-16-2010 12:56 PM
terminal command in c program eng_suha Linux - General 1 05-21-2010 12:09 PM
How to use c++ to use a command line program jboss1995 Programming 4 04-05-2008 11:22 PM
logger program or command? DJOtaku Linux - General 5 05-16-2005 02:22 AM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 09:19 AM


All times are GMT -5. The time now is 01:12 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration