Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
tkuchiki / ps_kill.sh
Created April 18, 2016 07:15
指定秒数経過したプロセスを kill
#!/bin/bash
epoch=$(sed -n 's/^btime //p' /proc/stat)
clk_tck=$(getconf CLK_TCK)
now=$(date +%s)
seconds=300
for pid in $(ps aux | grep jav[a] | awk '{print $2}'); do
start_time=$(awk '{print $22}' /proc/${pid}/stat)
ps_uptime=$(($now - ( $epoch + ($start_time / $clk_tck) ) ))
@tkuchiki
tkuchiki / jq.md
Last active July 14, 2021 08:34
example of jq

JSON to LTSV

jq -r '.[] | to_entries | map("\(.key):\(.value)") | join("\t")'

aws ec2 describe-instances の Tags に特定の文字列が含まれている PrivateIP のみ出力する

Tags がないとき用に .Tags[]? にしておく

@tkuchiki
tkuchiki / fluentd_buffer_stats.rb
Last active March 29, 2016 08:24
fluentd の plugin ごとの buffer_total_queued_size と buffer 使用率を出力する
#!/usr/bin/env ruby
require "net/http"
require "uri"
require "json"
require "optparse"
@args = {}
OptionParser.new do |opt|
opt.on("-p PORT", "--port PORT", "Port"){|v| @args[:port] = v }
@tkuchiki
tkuchiki / result.md
Last active August 15, 2019 03:28
[Openresty] %z だと nginx の iso_8601 の format と異なるので(: がない)、format を揃える
<source>
type forward
port 24224
</source>
<match **>
type forward
<server>
host test-server
</server>
@tkuchiki
tkuchiki / ec2-stop-and-start.sh
Created March 23, 2016 08:11
EC2 に force stop をかけて、stopped になったら start する
#!/bin/bash
INSTANCE="${1}"
instance_id() {
CODE="${2}"
if [ "${CODE}" = "" ]; then
aws ec2 describe-instances --filters "Name=tag:Name,Values=${1}" | jq -r ".Reservations[].Instances[].InstanceId"
else
@tkuchiki
tkuchiki / go-nginx-oauth2-adapter.spec
Created March 15, 2016 09:19
go-nginx-oauth2-adapter.spec
Summary: Authentication via nginx with ngx_http_auth_request_module, or h2o with mruby
Name: go-nginx-oauth2-adapter
Version: 0.1.0
Release: 1%{?dist}
License: MIT
Group: Applications/Services
URL: https://github.com/shogo82148/go-nginx-oauth2-adapter
%description
Authentication via nginx with ngx_http_auth_request_module, or h2o with mruby.
@tkuchiki
tkuchiki / main.go
Last active June 21, 2018 08:42
golang で timezone 変更
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
// current timezone & offset
@tkuchiki
tkuchiki / memo.md
Last active July 22, 2020 08:38
Jenkins の実行ユーザを変更する

実行ユーザ変更

/etc/sysconfig/jenkins

JENKINS_USER="USER"

を設定

@tkuchiki
tkuchiki / wait.sh
Last active February 10, 2016 03:41
wait コマンドの実験結果
#!/bin/bash
sleep 2 && echo "bar" &
sleep 1 && echo "foo" &
wait
echo "hogehoge"