The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Storing commands in $variables. Paulw0t Shell Programming and Scripting 7 08-08-2008 05:42 PM
Using variables in sed commands hcclnoodles Shell Programming and Scripting 2 01-02-2007 08:56 AM
Referencing variables in commands mharley Shell Programming and Scripting 3 03-31-2005 01:37 AM
Passing variables/arguments/parameters to commands Perderabo Answers to Frequently Asked Questions 0 06-13-2004 07:37 PM
Subing Variables with commands. Astudent UNIX for Dummies Questions & Answers 1 02-26-2001 05:02 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-28-2001
Astudent Astudent is offline
Registered User
  
 

Join Date: Oct 2000
Posts: 42
I have this idea.
I have a variable for the start of someones log in time,
(start=`who am i | cut -c30-34`)
and a variable for the log out time or present time,
(end=`date | cut -c12-16`)
but how do I go about subtracting them to get the total log in time.
I've tried adding a another variable total.
total=$end-$start, but that's just prints out everything in a numeric fashion.(2:30-2:10)
and if I use expr I get an error message saying "expr: non-numeric argument"

Now this seems simple but why won't this work.
Please Help.

theA
  #2 (permalink)  
Old 03-29-2001
PxT's Avatar
PxT PxT is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
This gets tricky because what if their login time is 2:59, and the logout time is 3:10. 3:10-2:59=? The shell doesn't know that you are trying to subtract times, it just sees numbers with a colon in the middle. A better way to do this might be to use the 'last' command, as one of the fields it provides is the total log in time.
  #3 (permalink)  
Old 03-30-2001
98_1LE 98_1LE is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2000
Location: Greater Dallas area
Posts: 405
Using last is the better solution, but there needs to be some logic coded in. The problem is the case where the user has been logged in for more than 24 hours, last gives you something like:

chuckb xdmremote sunws6:0 Tue Mar 27 07:36 - 13:45 (2+06:08)

In this case I have been logged in for more 2 days, 6 hours and 8 minutes.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0