get only the up time from uptime command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting get only the up time from uptime command
# 1  
Old 12-18-2008
Question get only the up time from uptime command

Hi all,Smilie
i am new to shell scripting and i have aproblem like i just want to extractthe uptime of the system from an uptime command which gives the output as the Current time , how long the system has been running,how many users are surrently logged on and the system load averages for past 1,5, and 15 mins.
from this i just need the time when system has been running.
can someone help me in that ?
Thanks
# 2  
Old 12-18-2008
something like this?
Code:
# uptime
 14:13:40 up 47 days, 19:37,  1 user,  load average: 0.45, 1.09, 0.75
# echo `uptime` | awk '{ print $3 " " $4 }'
47 days,

# 3  
Old 12-18-2008
i need the total time .. i.e 47days,19:37
# 4  
Old 12-18-2008
ya i got it
Thanks a lot Smilie
# 5  
Old 12-18-2008
Data need further help on this

on looking at the total time that system is up , i have few log files in my directory ..wat i want is depending on thheir timestmap i need to get only those files which has timestamp in the range that my system was up not before that.Can you help me on that even
For eg my present directory has :
-rw------- 1 tulip tulip 5533132 Dec 18 14:02 messages.log
-rw------- 1 tulip tulip 10405810 Dec 17 23:20 messages.log.01
-rw------- 1 tulip tulip 10278293 Dec 18 02:41 messages.log.02
-rw------- 1 tulip tulip 10414553 Dec 18 05:51 messages.log.03
-rw------- 1 tulip tulip 10406874 Dec 18 09:11 messages.log.04
-rw------- 1 tulip tulip 10229094 Dec 18 12:22 messages.log.05

and my uptime says up 17:28
hence i need only files that were created for 17hrs and 28mins ..
can someone helpme on this
this seems to be very tricky to me .. Smilie
# 6  
Old 12-19-2008
You may find it easier to use the timestamp of a file which was created during the boot process.
On most systems the boot time can be found with:
who -b

Then look in say /etc for a suitable file.
On my unix system /etc/rc.log is timestamped at the end of the boot process and does not change. (There is much variation of the boot process across unix versions).
If the precise timestamp is important, you could create a startup script yourself to make a timestamp file at the appropriate point in the boot sequence.

Then use find with the "-newer" switch:
find // -newer timestamp_filename -type f -print
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

uptime command output when the server is running more than one year?

What is the uptime command output when the server is running more than one year? My doubt is whether it show in number of days format or number years and number of days format? For example, Assume the server is running 400 days 3 hrs 3 min 3 secs. The output like 400 days 3:3 min or 1 year 5... (3 Replies)
Discussion started by: maruthu
3 Replies

2. Solaris

uptime command not showing how long the system has been up

Hello folks, uptime command not shows how long the system has been up. I know it come from a corruption of /var/adm/utmpx file. I've done : cat /dev/null > /var/adm/utmpx Now who and last commands work fine. But uptime still give me back an answer without the "up time". In which... (6 Replies)
Discussion started by: gogol_bordello
6 Replies

3. Shell Programming and Scripting

Extract the uptime from the output of the uptime command

Hi! I want to extract the uptime from the output of the uptime command. The output: 11:53 up 3:02, 2 users, load averages: 0,32 0,34 0,43 I just need the "3:02" part. How can I do this? Dirk (6 Replies)
Discussion started by: Dirk Einecke
6 Replies

4. UNIX for Dummies Questions & Answers

Difference between system uptime and last boot time.

My Linux system was last rebooted few hours ago. But it seems little confusing for me to figure out the exact reason behind it. I guess following command should justify what i meant to say. # date Wed May 11 13:22:49 IST 2011 # last | grep "May 10" reboot system boot 2.6.18-194.el5 ... (5 Replies)
Discussion started by: pinga123
5 Replies

5. Solaris

uptime and last reboot command in solaris

Hi, Can someone explain in detail what 'uptime' ,'last reboot' and 'who -b' commands do in solaris. this commands are not executing in every solaris box. why this is happening. Has solaris got some inbuilt commands into it. If yes then where i have found them? Thanks,Soubhik (6 Replies)
Discussion started by: soubmukh
6 Replies

6. AIX

reset the counter days for uptime command

hello, i send the uptime command in the AIX and the days that is UP 14652 days this is around 40 years, today is with the correct date&time, hos can I reset the counter days? somebody can help me? regards (3 Replies)
Discussion started by: timflr
3 Replies

7. Shell Programming and Scripting

Extracting load average from uptime command

The output ofthe uptime command gives: 9:40am up 9 days, 10:36, 4 users, load average: 0.02, 0.01, 0.00 How can i extract the portion "load average: 0.02, 0.01, 0.00". (3 Replies)
Discussion started by: proactiveaditya
3 Replies

8. AIX

After run ps , uptime , w command I get reply "killed"

Hi, After run ps , uptime , w command I get reply "killed" as normal dba and staff group user. As root every command works fine. I cheched all the user settings , right with other servers and I could not find any error and other settings. The oslevel is 5300-10-01-0921. Any idea to... (12 Replies)
Discussion started by: boki
12 Replies

9. UNIX for Dummies Questions & Answers

Differences between time command and usr/bin/time

I wondered if someone could point out the differences between the time commmand and usr/bin/time and the accuracy one might have over another. Also, is there a website or two a person could maybe link for me to describe the differences? Thank you for your time. (2 Replies)
Discussion started by: icedrake
2 Replies

10. UNIX for Dummies Questions & Answers

Interpretation of the uptime command

Hi there, do someone have detailed information how to interpret the uptime command or rather which values can be called normal? (i know what the information means, but i have no idea if these values are ok or to high: 3:02pm an 13:53, 2 Benutzer, Durchschnittslast: 10,06, 12,05, 13,00) ... (5 Replies)
Discussion started by: odin1999
5 Replies
Login or Register to Ask a Question