LoginSignup
22
25

More than 5 years have passed since last update.

linuxサーバの起動日時を知りたい

Posted at

このサーバ、いつ起動したっけ、と調べるのに、uptimeやtop、wコマンドで大雑把な起動時間を知ることができますが、何月何日何時何分に起動した?という問いかけに対しては計算しないといけません。

エレガントなコマンドがあるのかもしれませんが、現在時刻をUNIX Timeで取得して、/proc/uptimeの起動秒数から計算するワンライナーを書いてみました。

get_start_time.sh
date --date=@$(expr `date +%s` - `cut -d "." -f 1 /proc/uptime`)

exprは小数点を解釈できないので、cutで整数部分だけ切り出してます。bc使えば小数点の計算も可能ですが、手持ちの環境だとbcが入ってないサーバも多かったのでexprでやっております。

コマンド一発でいけるよって情報お待ちしてますw

22
25
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
25