Skip to content

Instantly share code, notes, and snippets.

View gb-swatanabe's full-sized avatar

Seigo Watanabe gb-swatanabe

View GitHub Profile
#!/bin/sh
# fb - file backup with timestamp and sequensal numbers
# usage : $0 filename [filename [...]]
today=`date '+%Y%m%d'`
for fn in $*
do
seq=''
#!/usr/bin/env perl
use strict;
use warnings;
my (%s) ;
$s{ "999999999999" } = '';
while (<>){
if( /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/ ){
$ ping x.x.x.x | ruby -rdate -pe 'BEGIN{$stdout.sync=true; trap(:INT){exit}}; print DateTime.now.strftime("\[%T\] ")'
$ ping x.x.x.x | perl -MPOSIX -pe 'BEGIN{ $|=1 } s/^/strftime "\[%T\] ", localtime(time)/e'
@gb-swatanabe
gb-swatanabe / 標準出力にタイムスタンプを付けるワンライナ(sed)
Created August 15, 2013 09:09
readに渡す前にsedで行頭に文字を追加しているのは、xに読み込まれたとき行頭の空白文字列が消えてしまうことへの対処です
$ ping x.x.x.x | sed -le 's/^/] /' | while read x; do echo "`date '+[%T'`$x"; done
@gb-swatanabe
gb-swatanabe / mysql-runtest.sh
Created August 15, 2013 09:19
一定間隔でテーブル更新を行う(レプリケーション構成での障害試験などを想定
#!/bin/bash
MYSQL_USER=root # mysql user
MYSQL_PWD=******** # mysql password
INTERVAL=1 # update interval (sec.)
export MYSQL_PWD
dbname=test_db
table=test_table
@gb-swatanabe
gb-swatanabe / send-mail.py
Last active June 13, 2016 23:39
mail send script with SMTP over SSL and SMTP-AUTH
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# send-mail.py - mail send script with SMTP over SSL and SMTP-AUTH
# usage: $0 [-n <sender name>] [-f <sender address>] <recipient address> <subject>
#----#----#----#----#----#----#----#----#----#----#----#----#----#----#----#
# 送信サーバ設定
mailserver = 'mailserver.example.com:25'
auth_user = 'username'
auth_pass = 'password'
@gb-swatanabe
gb-swatanabe / ouisearch.rb
Last active December 21, 2015 18:59
MACアドレスを引数に指定するとOUIベンダコードを検索するスクリプト (クエリ先: http://standards.ieee.org/develop/regauth/oui/public.html )
#!/usr/bin/env ruby
require "net/http"
query_url = 'http://standards.ieee.org/cgi-bin/ouisearch'
irregular = {
"080027" => "VirtualBox Guest",
"525400" => "QEMU/KVM Guest",
}
@gb-swatanabe
gb-swatanabe / ouisearch2.rb
Last active December 22, 2015 08:49
MACアドレスからベンダコードを検索するコード(oui.txtを利用)
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# oui.txtの入手方法:
# curl -O http://standards.ieee.org/develop/regauth/oui/oui.txt
# OUIデータベースの読み込み
def oui_store filename,o
# ファイルから読み込む
@gb-swatanabe
gb-swatanabe / pathmunge.sh
Created September 17, 2013 06:12
環境変数PATHへの追加削除(重複排除) - CentOS 6.x /etc/profileより抜粋
:
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else