Skip to content

Instantly share code, notes, and snippets.

@nna774
Last active February 7, 2017 11:21
Show Gist options
  • Save nna774/78a1d0d5451f286c8ee9359a0e98ff81 to your computer and use it in GitHub Desktop.
Save nna774/78a1d0d5451f286c8ee9359a0e98ff81 to your computer and use it in GitHub Desktop.
[Unit]
Description=8h
After=network.target
[Service]
ExecStart=/home/nona/.dotfiles/bin/8h.sh
Type=oneshot
[Install]
WantedBy=multi-user.target
#! /bin/sh -xe
WAIT=28800 # 8h
sleep ${WAIT}
/home/nona/.dotfiles/bin/slack.rb "<@U0323ESK6|nona7> もう${WAIT}秒も働き続けてるよ~~。そろそろ休んじゃダメ~?"
#! /usr/bin/ruby
# -*- encoding: utf-8 -*-
require 'json'
require "net/https"
WH_URI = "https://hooks.slack.com/services/~~~~~"
PER = 5400 #
def slack(msg)
uptime = `uptime`.chomp
hash = {
"text" => "#{msg} (uptime: #{uptime})",
"icon_emoji" => [":3:", ":3guru:", ":3heart:", ":3suya:", ":3oko:", ":3sake:"].sample,
"username" => `hostname`.chomp,
"channel" => "#nona-kanshi",
}.to_json
hash = "payload=" + hash
uri = URI.parse(WH_URI)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri)
req.body = hash
res = https.request(req)
puts res.body
end
END {
slack "おやすみ~"
}
start = Time.now
cnt = 1
while(true) do
diff = (Time.now - start).to_i
if (diff / PER).to_i > cnt then
cnt += 1
slack "<@U0323ESK6|nona7> もう#{diff}秒も働き続けてるよ~~。そろそろ休んじゃダメ~?"
end
sleep 1
end
#! /usr/bin/ruby
# -*- encoding: utf-8 -*-
require 'json'
require "net/https"
WH_URI = "https://hooks.slack.com/services/~~~~~"
uptime = `uptime`.chomp
hash = {
"text" => "#{ARGV[0]} (uptime: #{uptime})",
"icon_emoji" => [":3:", ":3guru:", ":3heart:", ":3suya:", ":3oko:", ":3sake:"].sample,
"username" => `hostname`.chomp,
"channel" => "#nona-kanshi",
}.to_json
hash = "payload=" + hash
uri = URI.parse(WH_URI)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(uri.request_uri)
req.body = hash
res = https.request(req)
puts res.body
@nna774
Copy link
Author

nna774 commented Feb 7, 2017

8h決め打ちなのがちょっと微妙な気もしなくもない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment