Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
69 lines (51 sloc) 1.92 KB
#!/usr/bin/ruby1.8
# -*- coding: utf-8 -*-
# Path: /system/thanks-chromebook-uptime.rb
# 크롬북 가동시간을 Gnus 메시지에 삽입합니다.
#
# #+BEGIN_SRC emacs-lisp
# (setq gnus-posting-styles
# '((".*"
# ("X-Chromebook-UPTIME" (shell-command-to-string "/system/thanks-chromebook-uptime.rb")))))
# #+END_SRC
# 크롬북(ChromeOS)과 Crouton 으로 설치된 우분투는 커널을 서로 공유합니다.
# ^고맙습니다 감사합니다_^))//
require "date"
tt = uptime_data = IO.read('/proc/uptime').split[0].to_i # 총 가동시간 (초단위)
sboot = Time.now - tt # 크롬북이 부팅된 시각
dt = tt/86400.to_i # 가동된 일수(days) 구하기
dtn = tt%86400 # 일수를 구하고 난후의 나머지값
ht = dtn/3600.to_i # 가동된 시간(hours) 구하기
htn = dtn%3600 # 시간을 구하고 난후의 나머지값
mt = htn/60.to_i # 가동된 분(minutes) 구하기
mtn = htn%60 # 분을 구하고 난후의 나머지값
if tt >= 86400
uptime = "#{dt}일 #{ht}시간 #{mt}분"
elsif tt >= 3600 && tt < 86400
uptime = "#{ht}시간 #{mt}분"
elsif tt >= 60 && tt < 3600
uptime = "#{mt}분 #{mtn}초"
else
uptime = "#{tt}초"
end
puts uptime.to_s + " (" + sboot.to_s + ")"
# 편집: Emacs 23.3 (Ubuntu 12.04)
# 마지막 갱신: 2017년 12월 20일
=begin
# Last comment: attached Python codes as same program.
# Tested by: Python 2.7.3 (Ubuntu 12.04)
#+BEGIN_SRC python
# -*- coding: utf-8 -*-
# 참고문헌: (System uptime in Python, a better way)
# http://planzero.org/blog/2012/01/26/system_uptime_in_python,_a_better_way
from datetime import timedelta
import datetime
tday = datetime.date.today()
with open('/proc/uptime', 'r') as f:
uptime_data = float(f.read().split()[0])
uptime_seconds = int(uptime_data)
uptime_string = str(timedelta(seconds = uptime_seconds))
stime_string = str(tday - timedelta(seconds = uptime_seconds))
print uptime_string, "(" + stime_string + ")"
#+END_SRC
=end