0

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.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
Diana
  • 1
  • 2

2 Answers2

0

You could adapt How to get a process uptime under different OS? to return the elapsed seconds of process 1 (init) as a pretty close approximation:

#!/bin/sh
t=$(LC_ALL=POSIX ps -o etime= -p 1)
d=0 h=0
case $t in *-*) d=$((0 + ${t%%-*})); t=${t#*-};; esac
case $t in *:*:*) h=$((0 + ${t%%:*})); t=${t#*:};; esac
s=$((10#$d*86400 + 10#$h*3600 + 10#${t%%:*}*60 + 10#${t#*:}))
printf '%d\n' "$s"
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
-1

Please use below one liner..

uptime=uptime | awk -F ',' ' {print $1" "$2}'|awk ' {print $3" "$4" "$5}' | sed '1,$s/:/ /' | awk ' {if ($4 =="users") print $1*60 + $2;else if ($4 =="user") print $1*60 + $2;else if ($2=="mins") print $1;else print $1*24*60 + $3*60 + $4}';if [ $uptime -lt 300 ]; then echo "Rebooted before 300 minutes"; else echo "OK"; fi