Skip to content

Instantly share code, notes, and snippets.

@hogem
hogem / drbddisk
Created July 30, 2014 07:58
/etc/ha.d/resource.d/drbddisk
#!/bin/bash
#
# This script is inteded to be used as resource script by heartbeat
#
# Copright 2003-2008 LINBIT Information Technologies
# Philipp Reisner, Lars Ellenberg
#
###
DEFAULTFILE="/etc/default/drbd"
@hogem
hogem / varnish-status.pl
Created May 26, 2013 00:55
print varnishstat
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use JSON;
my $q = CGI->new();
my $json = $q->param('json');
@hogem
hogem / etc_profile_logging
Created January 21, 2013 07:54
user history, terminal output logging (/etc/profile)
# Logging
if [ $UID -ne 0 ]; then
logdir_base="/var/log/user/$USER"
if [ -d $logdir_base ]; then
YYMM=$(date +%Y%m)
LOGDIR=$logdir_base/$YYMM
if [ ! -d $LOGDIR ]; then
mkdir -p $LOGDIR
fi
@hogem
hogem / getdents_loop_on_glusterfs_ext4.txt
Last active October 12, 2015 14:57
getdents loop on glusterfs distributed volume (ext4 filesystem)
# df -PT /mnt/vol1
Filesystem Type 1024-blocks Used Available Capacity Mounted on
sv01:/vol1 fuse.glusterfs 368136192 41472640 307963264 12% /mnt/vol1
# cd /mnt/vol1
# mkdir {0..9}
# dir=$(ls)
# for d in $dir; do dd if=/dev/zero of=./$d/hoge.dat bs=1M count=100; done
# strace ls *
execve("/bin/ls", ["ls", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], [/* 22 vars */]) = 0
@hogem
hogem / sys_guestfs_sample.pl
Created August 18, 2012 16:17
sys_guestfs_sample
use Sys::Guestfs;
my $h = Sys::Guestfs->new();
$h->add_drive_opts(
'disk.img',
readonly => 1,
format => 'qcow2',
);
$h->launch();
@hogem
hogem / get_libvirt_graphics_config.pl
Created June 18, 2012 02:58
get libvirt graphics config
use strict;
use warnings;
use Sys::Virt;
use XML::Simple;
use Data::Dump qw(dump);
my $user = 'user';
my $host = 'host';
my $vm = shift or die;
my $uri = "qemu+ssh://$user\@$host/system";
my $vmm = Sys::Virt->new(uri => $uri);
@hogem
hogem / backup_function.sh
Created May 17, 2012 07:28
引き数のファイルを日付付きでコピーするsh関数
## $ ls
## hoge
## $ bu hoge
## $ ls
## hoge hoge_yyyymmdd
bu (){
if [ $# -ne 1 ]; then
echo "bu: missing file operand"
@hogem
hogem / ascii_binary_convert.pl
Created May 17, 2012 04:32
convert ascii to binary, or binary to ascii
#!/usr/bin/perl
use strict;
use warnings;
## one liner
# perl -ne 'print unpack("H*", $_)' < ascii > binary
# perl -ne 'print pack("H*", $_)' < binary > ascii
my $mode = shift || help();
@hogem
hogem / sysvirt.pl
Created May 9, 2012 07:59
sample perl-Sys::Virt usage
#!/usr/bin/perl
use strict;
use warnings;
use Sys::Virt;
use Data::Dump qw(dump);
my $user = "user";
my $host = "host";
@hogem
hogem / make_symlinks_busybox_applets.pl
Created February 28, 2012 14:22
to make symlinks of busybox applets