Skip to content

Instantly share code, notes, and snippets.

@fanyeren
fanyeren / dmesg_time.sh
Created March 12, 2019 13:44
what does dmesg timestamp mean?
function dmesg_time() {
time=$1; shift;
date -d "1970-01-01 UTC `echo "$(date +%s)-$(cat /proc/uptime | cut -f 1 -d' ')+${time}" | bc ` seconds"
}
# usage: dmesg_time 27036930.869716
# output: Tue Mar 5 19:15:28 CST 2019
@fanyeren
fanyeren / build_number.sh
Last active April 8, 2019 12:56
buildNumber
#!/bin/bash
BUILD_NUM=""
if [[ ! -f buildNumber ]]; then
touch buildNumber
BUILD_NUM="b-0"
echo 0 > buildNumber
else
num=$(cat buildNumber | grep -E '^[0-9]+$' 2>/dev/null)
@fanyeren
fanyeren / oom_score_and_pid.sh
Last active February 21, 2019 09:51
计算所有 oom score 大于 100 的 pid 和 对应的 cmdline
#!/bin/bash
for score_file in `ls /proc/*/oom_score 2>/dev/null`;
do
score=$(cat $score_file 2>/dev/null);
if [[ x$score != 'x' ]]; then
if [[ $score > 100 ]]; then
pid=$(echo $score_file 2>/dev/null | awk -F'/' '{print $3}')
if [[ x$pid != 'x' ]]; then
@fanyeren
fanyeren / idle_ratio.sh
Created March 7, 2016 08:13
linux 空闲率计算
#!/bin/bash
cc=$(grep -c processor /proc/cpuinfo)
uptime=$(cat /proc/uptime | awk '{print $1}')
idletime=$(cat /proc/uptime | awk '{print $2}')
idle_ratio=$(echo $cc $uptime $idletime | perl -ne '{my @input = split(/\s+/, $_); my $idle = $input[2] / ($input[0] * $input[1]); print $idle, "\n";}')
idle_ratio=$(printf "%.04s" $idle_ratio)
echo -e "\t\t\t\t\t\e[1;31m开机以来空闲率:$idle_ratio\e[0m\n"
#!/bin/sh
#
# rabbitmq-server RabbitMQ broker
#
# chkconfig: - 80 05
# description: Enable AMQP service provided by RabbitMQ
#
### BEGIN INIT INFO
# Provides: rabbitmq-server
@fanyeren
fanyeren / sendemail.pl
Created November 4, 2013 07:13
sendemail.pl
#!/usr/bin/perl -w
##############################################################################
## sendEmail
## Written by: Brandon Zehm <[email protected]>
##
## License:
## sendEmail (hereafter referred to as "program") is free software;
## you can redistribute it and/or modify it under the terms of the GNU General
## Public License as published by the Free Software Foundation; either version
## 2 of the License, or (at your option) any later version.
@fanyeren
fanyeren / gem
Created October 7, 2013 11:02
gem
https://github.com/square/kochiku
@fanyeren
fanyeren / cpan
Last active December 24, 2015 21:19
cpan modules
https://metacpan.org/favorite/leaderboard
https://github.com/reyjrar/es-utils
https://github.com/jprante/Elasticsearch-Dancer-App
Log::Dispatch::Message::Passing
Elasticsearch
App::ElasticSearch::Utilitie
@fanyeren
fanyeren / .rvimrc
Created September 28, 2013 13:35
.rvimrc
rvm --create use ruby-1.9.3@pisa-op
@fanyeren
fanyeren / is_robot.pl
Created September 26, 2013 14:11
is_robot.pm borrowed from fayland
sub is_robot {
my ($agent) = @_;
return 1 if is_site_robot($agent);
return 1 if is_program_robot($agent);
return;
}
sub is_site_robot {