Connected time on UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Connected time on UNIX
# 1  
Old 01-20-2014
Connected time on UNIX

Hello,

A question please.

Could anyone tell me how to know the connected time for a user on unix ?

I'd need to know this information for several days.

Is there a command to get it ?

Thanks in advance
# 2  
Old 01-20-2014
For an interactive shell with a terminal:
Code:
who am i

Further you can query the current shell process for elapsed time and start time:
Code:
ps -p $$ -o etime
ps -p $$ -o stime

BTW you can suppress the header line with
Code:
ps -p $$ -o etime=
ps -p $$ -o stime=


Last edited by MadeInGermany; 01-20-2014 at 08:05 AM..
# 3  
Old 01-20-2014
Thanks MadeInGermany.

Do you know how could I query for passed days, for example 18/01 and 19/01 ?

greetings
# 4  
Old 01-20-2014
Hmm, date calculation can become complicated.
GNU date has
Code:
date --date "-1 days"
date --date "-2 days"

On standard Unix you should have a look at
Yesterdays Date/Date Arithmetic | Unix Linux Forums | Answers to Frequently Asked Questions
An example to check the current process' etime against the two previous days:
Code:
etime=`ps -p $$ -o etime=`
case $etime in
(*-*) edays=${etime%-*};;
(*) edays=0;;
esac
if [ $edays -eq 1 -o $edays -eq 2 ]; then
  echo "the current process is 1-2 days old"
fi

NB some of these expressions only work in Posix shells (ksh, bash, zsh).

Last edited by MadeInGermany; 01-20-2014 at 08:36 AM.. Reason: bug fix
# 5  
Old 01-20-2014
Did you try the last command?
# 6  
Old 01-20-2014
Hi Rudic,

I tried LAST command, but I only get the users logged in today only, not for passed days.

I am not an experimented guy on unix.

Thanks
# 7  
Old 01-20-2014
man last:
Quote:
DESCRIPTION Last searches back through the file /var/log/wtmp (or the file desig- nated by the -f flag) and displays a list of all users logged in (and out) since that file was created.
What be the creation date of your /var/log/wtmp?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Arduino UNIX Time - Syncing Computer UNIX Time to Arduino Time with Python

Just finished a quick Python script to send the current unix time over to the Arduino from macOS, so in the absence of GPS or some other way to get the unix timestamp (epoch time) to the Arduino, I can get my macOS and Arduino UNO synced to within a second. Normally, when the Arduino starts... (9 Replies)
Discussion started by: Neo
9 Replies

2. UNIX for Beginners Questions & Answers

Sun Ray 3 UNIX Lab not connected to Solaris 10 Server

All 30 of my students in the Linux Lab here at school have the same message showing on their screen when they try to log into the server. How can we Authenticate the Server and fix the missing specific parameters on the Solaris Server to fix this issue ?? (6 Replies)
Discussion started by: mwilliams21z
6 Replies

3. Shell Programming and Scripting

Convert UTC time into current UNIX sever time zone

Hi guys thanks for the help for my previous posts.Now i have a requirement that i download a XMl file which has UTC time stamp.I need to convert UTC time into Unix server timezone. For ex if the time zone of unix server is CDT then i need to convert into CDT.whatever may be the system time... (5 Replies)
Discussion started by: mohanalakshmi
5 Replies

4. Shell Programming and Scripting

Unix server to Hard-drive connected on the machine

Hi, I have an external hard drive connected to my iMac. I am logged into a Linux_x86_64 server. Now, if I want to download files directly to the hard drive, is there a way to do it. Currently, I am chasing cyberduck to download content to the hard drive. (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Shell script to display user logged last week and time connected

Hello all, I want to display all the user logged last week and know the time tnat they are connected. I have been looking for a solution in the Forum, but I didn't find. Thanks in advance (4 Replies)
Discussion started by: ahernandez
4 Replies

6. UNIX for Dummies Questions & Answers

How to determine if a host is connected to the Internet in Unix?

How to determine if a host is connected to the Internet in Unix ? (1 Reply)
Discussion started by: shuhang2
1 Replies

7. UNIX for Dummies Questions & Answers

How to input EOF from Windows connected to Unix maxhine via SSH

Hi, I'm connected remotely to a unix machine and my machine is running windows and I'm trying to write a C program that's taking input from stdin. How do I enter the 'EOF' character from my keyboard? (in UNIX it would be ctrl-D). I read somewhere that its ctrl-Z, but when I do that the window... (2 Replies)
Discussion started by: sayeo
2 Replies

8. UNIX for Advanced & Expert Users

How To Provide Time Sync Using Nts-150 Time Server On Unix Network?

can anybody tel lme,how to instal NTS -150 on a unix network,it needs some patch to fetch time frm serve,,?? (2 Replies)
Discussion started by: pesty
2 Replies

9. AIX

HMC and Unix Box not connected

Hi There, I'm new here and this is my first (of many ;) ) problems. I've got AIX 5.3 on our unix box and i'm trying to do a DLPAR memory change, but then I ok it I get an error telling me that there is no RMC connection. Does anyone have any ideas what could cause this? Thanks in advance. ... (3 Replies)
Discussion started by: KeesH
3 Replies
Login or Register to Ask a Question