Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
0
votes
2
answers
3049
views
How to get server uptime of AIX server results in seconds
In Linux, I can get the server uptime results in seconds (value) by using below command ``` cat /proc/uptime ``` But in AIX, we do not have `uptime` in `/proc`. If I just type `uptime`, I get results in days, hours, minutes, but I want to get the output only in seconds like 86400 seconds or 30 secon...
In Linux, I can get the server uptime results in seconds (value) by using below command
cat /proc/uptime
But in AIX, we do not have uptime
in /proc
. If I just type uptime
, I get results in days, hours, minutes, but I want to get the output only in seconds like 86400 seconds or 30 seconds or any value.
With this output, I want to set an alert from SCOM monitoring tool to create alerts if it is less than 1800 seconds.
From SCOM, I can run a shell command.
Diana
(1 rep)
Apr 1, 2020, 07:44 PM
• Last activity: Jul 7, 2025, 04:04 PM
0
votes
3
answers
2500
views
Time in seconds since boot on AIX
I need to get the number of seconds since the last reboot, using ksh. What is the command or function to achieve this?
I need to get the number of seconds since the last reboot, using ksh.
What is the command or function to achieve this?
Venkat Teki
(347 rep)
Mar 17, 2016, 10:22 AM
• Last activity: Feb 5, 2025, 01:19 PM
9
votes
1
answers
30067
views
The amount of time since the system was last booted
I have used both `uptime` and `cat /proc/uptime` commands. I know the idle time in the later can be greater than running time (multiprocessors). However, when I add both running and idle times, and compare it to the `uptime` (5:30 hrs) they are not equal. I assume it's because the `uptime` returns t...
I have used both
uptime
and cat /proc/uptime
commands. I know the idle time in the later can be greater than running time (multiprocessors). However, when I add both running and idle times, and compare it to the uptime
(5:30 hrs) they are not equal. I assume it's because the uptime
returns the real time and the cat /proc/uptime
returns processor(s) time.
Short things clear, I want to know the reason exactly and I want to know which one to choose, according to the topic.
Also, is it possible to get the processor(s) time in the last **24 hours?**
**NOTE:** Please read this article to understand where this is going.
*Distributor ID: Ubuntu
Description: Ubuntu 12.04.2 LTS
Release: 12.04
Codename: precise
*
Atieh
(233 rep)
Jan 21, 2014, 04:15 PM
• Last activity: Nov 14, 2024, 04:48 AM
12
votes
5
answers
24573
views
Convert linux sysuptime to well format date
I want to display `/proc/uptime` in well format as: DD:HH:MM:SS `/proc/uptime` give me up time of system in seconds, is there a standard solution that convert seconds to this format?
I want to display
/proc/uptime
in well format as:
DD:HH:MM:SS
/proc/uptime
give me up time of system in seconds, is there a standard solution that convert seconds to this format?
Navid Farhadi
(411 rep)
Mar 12, 2012, 03:53 PM
• Last activity: Apr 11, 2024, 10:25 PM
1
votes
7
answers
1211
views
System uptime without ssh login
I have many linux servers which **I would like to check uptime** but I have to login to every one. Is this possible to check linux server running time **without ssh login** to it? PS. My distributions are RHEL 7/8 and OL 8.
I have many linux servers which **I would like to check uptime** but I have to login to every one. Is this possible to check linux server running time **without ssh login** to it?
PS. My distributions are RHEL 7/8 and OL 8.
sk1me
(113 rep)
Nov 17, 2022, 07:36 AM
• Last activity: Feb 16, 2024, 04:39 AM
0
votes
2
answers
289
views
Did my Linux host restart?
I am running AlmaLinux 9, and it has been running stable for some time. This morning I received email messages that a systemd service had restarted on its own overnight. Strange, since this service is NOT set to autorestart, just start with system. The host is on a UPS so there shouldn't have been a...
I am running AlmaLinux 9, and it has been running stable for some time. This morning I received email messages that a systemd service had restarted on its own overnight. Strange, since this service is NOT set to autorestart, just start with system. The host is on a UPS so there shouldn't have been any strange power issues. I checked the boot log, and the "last" command shows:
reboot system boot 5.14.0-284.25.1. Mon Nov 20 02:15 still running
reboot system boot 5.14.0-284.25.1. Sun Oct 29 15:24 still running
reboot system boot 5.14.0-284.25.1. Thu Oct 26 10:57 - 11:07 (2+00:09)
reboot system boot 5.14.0-284.25.1. Wed Oct 25 17:13 - 17:16 (00:03)
reboot system boot 5.14.0-284.25.1. Fri Oct 20 11:56 - 17:10 (5+05:13)
reboot system boot 5.14.0-284.25.1. Wed Oct 18 20:25 - 11:51 (15:26)
reboot system boot 5.14.0-284.25.1. Tue Oct 17 04:52 - 11:51 (2+06:59)
reboot system boot 5.14.0-284.25.1. Fri Sep 29 15:45 - 11:51 (19+20:06)
reboot system boot 5.14.0-284.25.1. Sat Sep 23 09:09 - 14:56 (6+05:46)
reboot system boot 5.14.0-284.25.1. Tue Sep 19 20:14 - 09:09 (3+12:55)
reboot system boot 5.14.0-284.25.1. Tue Sep 19 19:21 - 19:57 (00:35)
reboot system boot 5.14.0-284.25.1. Sun Sep 10 20:23 - 18:01 (8+21:37)
reboot system boot 5.14.0-284.25.1. Sun Sep 10 16:18 - 20:23 (04:04)
reboot system boot 5.14.0-284.25.1. Fri Sep 8 20:53 - 19:56 (23:03)
reboot system boot 5.14.0-284.25.1. Fri Sep 8 20:43 - 20:52 (00:08)
reboot system boot 5.14.0-284.25.1. Fri Sep 8 20:27 - 20:43 (00:15)
reboot system boot 5.14.0-284.25.1. Fri Sep 8 19:10 - 20:26 (01:16)
reboot system boot 5.14.0-284.25.1. Fri Sep 8 16:25 - 18:52 (02:26)
reboot system boot 5.14.0-284.11.1. Fri Sep 8 19:50 - 16:24 (-3:25)
Which doesn't make sense...how can the top two lines both be "still running"? Or am I misinterpreting what this means?
I check uptime --pretty and it says:
up 8 hours, 49 minutes
Yet my /var/log/messages file does not show any system restart related messages around 9 hours ago...just regular logging.
What is going on? Uptime says my host rebooted this morning, "last" says the Oct 29 start is still running (but so is a Nov 20 / today start), and the system logs shows no indication of a restart in the last 24 hours. This makes no sense
TSG
(1983 rep)
Nov 20, 2023, 03:11 PM
• Last activity: Nov 20, 2023, 05:28 PM
1
votes
1
answers
587
views
Get total time system has been used today - in minutes
I want to set a daily limit as to how long my computer can be on in a single day. In order to do so, I'm writing a cron script that will take appropriate action when certain milestones are reached (showing an alert when time is running out; shutting down the computer when time is up). The part I'm s...
I want to set a daily limit as to how long my computer can be on in a single day. In order to do so, I'm writing a cron script that will take appropriate action when certain milestones are reached (showing an alert when time is running out; shutting down the computer when time is up).
The part I'm struggling with is getting the total uptime in minutes for the day. I have looked at this uptime script , but I feel that using last is simplest.
$ last -s today
Gives me something like:
user tty1 Sat Jul 22 14:09 still logged in
user tty1 Sat Jul 22 11:50 - down (01:56)
I am currently trying to convert the hours in parentheses to minutes, and also converting the 'still logged in' session to minutes. It can work, but I feel like all these options are a bit convoluted.
Is there a simpler way to get the total uptime (excluding suspend/sleep) in minutes, or should I find a workaround for these types of outputs?
macwirb
(11 rep)
Jul 22, 2023, 05:11 PM
• Last activity: Jul 24, 2023, 08:49 AM
0
votes
1
answers
480
views
MT9721K wireless adapter Drivers randomly stop working on debian and ubuntu based systems
After a certain amount of uptime, the OS is irreversably unable to detect the wireless adapter (MT7921K in this case). I previously "fixed" this by restoring the original Windows 11 install and then installing Debian 12 -- this worked, but I didn't realize long uptimes were the cause and now it has...
After a certain amount of uptime, the OS is irreversably unable to detect the wireless adapter (MT7921K in this case). I previously "fixed" this by restoring the original Windows 11 install and then installing Debian 12 -- this worked, but I didn't realize long uptimes were the cause and now it has once again stopped working.
I found this askubuntu post but unlike that user, it seems like I have multiple aliases assigned to the mt7921e module. I'm not sure how to solve this problem, and would appreciate any help. Thank you.
OS: Debian GNU/Linux 12 (bookworm) x86
Host: Modern 14 C7M REV:1.0
Kernel: 6.1.0-10-amd64
Network controller : MEDIATEK Corp. MT7921K (RZ608) Wi-Fi 6E 80MHz [14c3:0608]
Subsystem: MEDIATEK Corp. MT7921K (RZ608) Wi-Fi 6E 80MHz [14c3:0608]
user@localhost ~> sudo modinfo mt7921e | grep alias
alias: pci:v000014C3d00000616sv*sd*bc*sc*i*
alias: pci:v000014C3d00000608sv*sd*bc*sc*i*
alias: pci:v000014C3d00007922sv*sd*bc*sc*i*
alias: pci:v000014C3d00007961sv*sd*bc*sc*i*
Update: I followed the advice in this post and did a 60-second hold on the power button. Upon rebooting there was a "secure boot violation". I disabled secure boot and booted successfully into the desktop to find that my wifi was indeed working. However, my touchpad has stopped working.
Update 2: On the previous boot I had my mouse plugged in during boot. I removed the mouse and rebooted, and after booting the touchpad was recognized and the mouse worked as well.
Dactorwatson
(1 rep)
Jul 9, 2023, 12:34 AM
• Last activity: Jul 9, 2023, 04:42 PM
0
votes
2
answers
2377
views
Why is load average being reported as 0.00 though system is busy doing work?
`uptime`, `top`, `cat /proc/loadavg` all reporting load averages for the last 1/5/15 minutes as `0.00`, but the system is definitely busy doing work. Why is this? Server is running Red Hat Enterprise Linux Server release 6.6, kernel 2.6.32-504.12.2.el6.x86_64. $ uptime 12:13:44 up 73 days, 8 min, 1...
uptime
, top
, cat /proc/loadavg
all reporting load averages for the last 1/5/15 minutes as 0.00
, but the system is definitely busy doing work. Why is this? Server is running Red Hat Enterprise Linux Server release 6.6, kernel 2.6.32-504.12.2.el6.x86_64.
$ uptime
12:13:44 up 73 days, 8 min, 1 user, load average: 0.00, 0.00, 0.00
$ cat /proc/loadavg
0.00 0.00 0.00 12/2706 39700
$ top
top - 12:15:35 up 73 days, 10 min, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 572 total, 4 running, 568 sleeping, 0 stopped, 0 zombie
Cpu(s): 37.1%us, 2.3%sy, 0.0%ni, 42.0%id, 18.0%wa, 0.0%hi, 0.5%si, 0.0%st
...
user117452
May 31, 2015, 12:18 AM
• Last activity: Jun 26, 2023, 01:04 PM
3
votes
2
answers
788
views
Format the output of "read_file uptime" in i3status
I'm trying to display my system uptime with i3status. This is what I have in my `i3status.conf` file: read_file uptime { format = "%title: %content" path = "/proc/uptime" } However the output is in seconds, as can be seen in this screenshot, which is obviously not ideal: [
Zsargul
(101 rep)
Dec 20, 2021, 03:19 PM
• Last activity: May 20, 2023, 06:15 PM
19
votes
4
answers
30594
views
Why/how does "uptime" show CPU load >1?
I have a **1 core CPU** installed on my PC. Sometimes, ``uptime`` shows load >1. How is this possible and what does this mean? EDIT: The values go up to ``2.4``
I have a **1 core CPU** installed on my PC. Sometimes, `
uptime
` shows load >1. How is this possible and what does this mean?
EDIT: The values go up to `2.4
`
Frantisek
(415 rep)
Mar 4, 2014, 08:20 PM
• Last activity: Mar 4, 2023, 05:32 PM
5
votes
2
answers
7030
views
How do I get the time when the system booted up in epoch format?
I need to write a script that figures out if a reboot has occurred after an RPM has been installed. It is pretty easy to get the epoch time for when the RPM was installed: `rpm -q --queryformat "%{INSTALLTIME}\n" glibc | head -1`, which produces output that looks like this: `1423807455`. This cross...
I need to write a script that figures out if a reboot has occurred after an RPM has been installed. It is pretty easy to get the epoch time for when the RPM was installed:
rpm -q --queryformat "%{INSTALLTIME}\n" glibc | head -1
, which produces output that looks like this: 1423807455
.
This cross checks with rpm -q --info
.
# date -d@rpm -q --queryformat "%{INSTALLTIME}\n" glibc | head -1
Fri Feb 13 01:04:15 EST 2015
# sudo rpm -q --info glibc | grep "Install Date" | head -1
Install Date: Fri 13 Feb 2015 01:04:15 AM EST Build Host: x86-022.build.eng.bos.redhat.com
But I am getting stumped on trying to figure out how to get the epoch time from uptime
or from cat /proc/uptime
. I do not understand the output from cat /proc/uptime
which on my system looks like this: 19496864.99 18606757.86
. Why is there two values? Which should I use and why do these numbers have a decimal in them?
UPDATE: thanks techraf
here is the script that I will use ...
#!/bin/sh
now=date +'%s'
rpm_install_date_epoch=rpm -q --queryformat "%{INSTALLTIME}\n" glibc | head -1
installed_seconds_ago=expr $now - $rpm_install_date_epoch
uptime_epoch=cat /proc/uptime | cut -f1 -d'.'
if [ $installed_seconds_ago -gt $uptime_epoch ]
then
echo "no need to reboot"
else
echo "need to reboot"
fi
I'd appreciate any feedback on the script.
Thanks
Red Cricket
(2233 rep)
Mar 24, 2016, 09:38 PM
• Last activity: Feb 15, 2023, 04:12 PM
10
votes
3
answers
69748
views
How to know why server keeps restarting?
It seems that my server keeps restarting. I want to know why. How can I know when the last time server was rebooted and why? root pts/0 139.193.156.125 Thu Aug 8 21:10 still logged in reboot system boot 2.6.32-358.11.1. Thu Aug 8 20:38 - 21:11 (00:33) reboot system boot 2.6.32-358.11.1. Thu Aug 8 20...
It seems that my server keeps restarting. I want to know why.
How can I know when the last time server was rebooted and why?
root pts/0 139.193.156.125 Thu Aug 8 21:10 still logged in
reboot system boot 2.6.32-358.11.1. Thu Aug 8 20:38 - 21:11 (00:33)
reboot system boot 2.6.32-358.11.1. Thu Aug 8 20:15 - 21:11 (00:56)
reboot system boot 2.6.32-358.11.1. Thu Aug 8 19:16 - 21:11 (01:55)
reboot system boot 2.6.32-358.11.1. Thu Aug 8 18:56 - 21:11 (02:14)
reboot system boot 2.6.32-358.11.1. Thu Aug 8 18:24 - 21:11 (02:47)
root pts/1 139.193.156.125 Thu Aug 8 18:16 - crash (00:07)
root pts/0 195.254.135.181 Thu Aug 8 18:10 - crash (00:13)
reboot system boot 2.6.32-358.11.1. Thu Aug 8 17:52 - 21:11 (03:19)
root pts/0 195.254.135.181 Thu Aug 8 17:38 - crash (00:13)
reboot system boot 2.6.32-358.11.1. Thu Aug 8 17:08 - 21:11 (04:02)
reboot system boot 2.6.32-358.11.1. Thu Aug 8 16:58 - 21:11 (04:12)
reboot system boot 2.6.32-358.11.1. Thu Aug 8 16:45 - 21:11 (04:26)
reboot system boot 2.6.32-358.11.1. Thu Aug 8 16:35 - 21:11 (04:36)
reboot system boot 2.6.32-358.11.1. Thu Aug 8 16:27 - 21:11 (04:44)
reboot system boot 2.6.32-358.11.1. Thu Aug 8 15:59 - 21:11 (05:12)
reboot system boot 2.6.32-358.11.1. Thu Aug 8 06:15 - 21:11 (14:56)
root pts/1 208.74.121.102 Wed Aug 7 06:03 - 06:04 (00:00)
root pts/1 208.74.121.102 Tue Aug 6 15:34 - 17:40 (02:05)
root pts/0 139.193.156.125 Tue Aug 6 11:28 - 04:40 (1+17:11)
In Linux is there ANY WAY to know why the system rebooted? Specifically did high load cause it? If not that then What?
user4951
(10749 rep)
Aug 9, 2013, 03:10 AM
• Last activity: Oct 6, 2022, 01:42 PM
-1
votes
3
answers
2456
views
Finding the Percentage from a grep variable
I want to display the calculation of the CPU load in percentage. num2=$(uptime | grep "average:" | tr -d " " | cut -d ':' -f 5 | cut -d ',' -f 2) percent=$((num2(*100))) echo 'CPU percentage' $percent Am I missing something?
I want to display the calculation of the CPU load in percentage.
num2=$(uptime | grep "average:" | tr -d " " | cut -d ':' -f 5 | cut -d ',' -f 2)
percent=$((num2(*100)))
echo 'CPU percentage' $percent
Am I missing something?
Zigbii
(125 rep)
Dec 28, 2018, 07:01 PM
• Last activity: Sep 14, 2022, 11:09 AM
4
votes
2
answers
2395
views
CPU and Load Average Conflict on EC2 server
I am having touble understanding what server resource is causing lag in my Java game server. In the last patch of my game server, I updated my EC2 lamp server from **apache2.2, php5.3, mysql5.5** to **apache2.4, php7.0, mysql5.6**. I also updated my game itself, to include many more instances of mon...
I am having touble understanding what server resource is causing lag in my Java game server. In the last patch of my game server, I updated my EC2 lamp server from **apache2.2, php5.3, mysql5.5** to **apache2.4, php7.0, mysql5.6**. I also updated my game itself, to include many more instances of monsters that are looped though every game loop - among other things.
Here is output from right when my game server starts up:
Here is output from a few minutes later:
And here is output from the next morning:
As you can see in the images the cpu usage of my Java process levels off around 80% in the last screenshot, yet load avg goes to 1.20. I have even seen it go as high as 2.7 this morning. The cpu credits affect how much actual cpu juice my server has so it makes sense that the percentage goes up as my credits balance diminishes, but why at 80% does my server lag?
On my Amazon EC2 metrics I see cpu at 10% (which confuses me even more):
Right when I start up my server my mmorpg does not lag at all. Then as soon as my cpu credits are depleted it starts to lag. This makes me feel like it is cpu based, but when I see 10% and 80% I don't see why. Any help would be greatly appreciated. I am on a T2.micro instance, so it has 1 vCPU. If I go up to the next instance it nearly doubles in price, and stays at same vCPU of 1, but with more credits.
Long story short, I want to understand fully what I going on as the 80% number is throwing me. I don't just want to throw money at the problem.




KisnardOnline
(143 rep)
Feb 25, 2017, 03:46 PM
• Last activity: Aug 9, 2022, 06:10 AM
1
votes
1
answers
1021
views
Convert string time to seconds
I'm receiving an uptime in this format: 167h58m10.586582048s I want to transform it to seconds and discard the fraction part. I know `awk` could do that if only the received string had the same separator. That's not the case. How could I convert that to seconds?
I'm receiving an uptime in this format:
167h58m10.586582048s
I want to transform it to seconds and discard the fraction part.
I know
awk
could do that if only the received string had the same separator. That's not the case.
How could I convert that to seconds?
markfree
(425 rep)
Feb 3, 2022, 01:35 AM
• Last activity: Feb 3, 2022, 06:45 AM
0
votes
0
answers
106
views
What is the most efficient way to run a task every X hours of runtime, accumulated over all power-ons?
Let us assume that I have a machine which wakes up at 7:00, does some work, usually for 15 minutes, but sometimes for days (e.g., experiment supervision), and after the works is done, it powers itself off. I want to run a certain analysis tool at each 10 hours of runtime. This may happen to be every...
Let us assume that I have a machine which wakes up at 7:00, does some work, usually for 15 minutes, but sometimes for days (e.g., experiment supervision), and after the works is done, it powers itself off.
I want to run a certain analysis tool at each 10 hours of runtime. This may happen to be every 40 days if the machine only spends 15 minutes every day, but it may need to run twice a day if there is a lot of work for the machine to do.
How would I achieve this?
What comes immediately to mind is to dump "uptime" into a log file by a bash loop, and read it, still, every minute, to sum the uptimes since the last analysis tool run. When the desired time comes, inhibit shutdown (how would I do that?), do the analysis, and shutdown manually.
This would work, but is (1) very I/O intensive, (2) hacky, and (3) failing if analysis itself takes more than 10 hours, which may happen.
Is there a better way?
Vladimir Nikishkin
(31 rep)
Dec 29, 2021, 06:09 AM
6
votes
6
answers
7505
views
Finding PC uptime from first day until now
I need to find PC uptime from the day of installation until now. Is this logged somewhere? Does any file log this cumulative uptime?
I need to find PC uptime from the day of installation until now.
Is this logged somewhere? Does any file log this cumulative uptime?
Chalist
(417 rep)
Dec 26, 2012, 08:35 AM
• Last activity: Dec 18, 2021, 02:28 PM
1
votes
1
answers
1152
views
Is it possible to detect that an impending shutdown (or reboot) is in progress?
I'm trying to write a script in bash that I intend to start on system startup and end on system shutdown. The idea is to create a system uptime tracker for myself. For the purpose, I want to save the uptime of each day in a file. But I can't figure out a way to know when a shutdown has been triggere...
I'm trying to write a script in bash that I intend to start on system startup and end on system shutdown. The idea is to create a system uptime tracker for myself.
For the purpose, I want to save the uptime of each day in a file. But I can't figure out a way to know when a shutdown has been triggered by the user (or by the system). This is very important because otherwise I won't be able to save the session end time in the file.
Also it could have been done by running a loop after some x amount of time and saving the current uptime. But I think it's inefficient and at the same time will perform unnecessary disk operations.
There might be readymade solutions available for this (or perhaps a native command), but I want to code it myself.
Shourya Shikhar
(169 rep)
Dec 18, 2021, 11:57 AM
• Last activity: Dec 18, 2021, 12:51 PM
3
votes
1
answers
3716
views
last reboot and who -b shows different results?
I am using the following 3 commands to check the latest time point when my computer is rebooted: ``` last reboot who -b uptime ``` The result for last reboot is: ``` wtmp begins Sat Oct 9 04:49:27 2021 ``` The result for who -b is: ``` system boot 2018-01-11 20:52 ``` The result for uptime is: ``` 2...
I am using the following 3 commands to check the latest time point when my computer is rebooted:
last reboot
who -b
uptime
The result for last reboot is:
wtmp begins Sat Oct 9 04:49:27 2021
The result for who -b is:
system boot 2018-01-11 20:52
The result for uptime is:
22:49:01 up 1372 days, ...
It seems that the result of uptime and who -b is consistent with each other, but inconsistent with that of last reboot.
I find this post https://unix.stackexchange.com/questions/18413/uptime-and-who-b-are-showing-different-times-when-the-system-was-last-booted-on , but it said his uptime and who -b is inconsistent with each other, different from my case.
alancc
(213 rep)
Oct 15, 2021, 05:58 AM
• Last activity: Oct 15, 2021, 08:57 PM
Showing page 1 of 20 total questions