Hunter的大杂烩 技术学习笔记

2014-09-11

bash执行命令各种情况分析

Filed under: 技术话题 — hunter @ 9:30 pm

from: http://blog.csdn.net/smstong/article/details/18352619

Linux系统中的可执行文件有多少种类?bash环境下是如何执行程序的?下面逐一分析。

1 Linux系统中可执行文件种类

1.1 二进制可执行文件

这种文件是最常见的,如/bin/ls,/sbin/ifconfig, /bin/cat等等。

[root@notebook135 ~]# file /bin/ls /bin/cat /sbin/ifconfig

/bin/ls:        ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

/bin/cat:       ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

/sbin/ifconfig: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

(more…)

bash 里的定时器

Filed under: 技术话题 — hunter @ 9:29 pm

from:http://blog.chinaunix.net/uid-600330-id-2088714.html


#function : begin_timer HANDLER_NAME MICROSECONDS CMD_ON_TIMEOUT ARGS...
# @HANDLER_NAME : handler of timer
# @MICROSECONDS : micro seconds to wait
# @CMD_ON_TIMEOUT ARGS : command and its arguments to run when timeout
start_timer(){
[ $# -lt 2 ] && return 1
HANDLER=$1
TIMER=$2
shift 2
(
trap exit USR1
sleep $TIMER
"$@"
)&
eval export $HANDLER=$!
}
export -f start_timer
(more...)

Bash编程陷阱一

Filed under: 技术话题 — hunter @ 9:28 pm

from:http://www.oenhan.com/bash-pitfalls-1

Bash编程陷阱:bash-pitfalls里面介绍了43条shell陷阱,都是一些很常见的应用场景,新手和老手都有可能犯的错误,为了加深记忆,自己就大致记录下来,英文文章用wiki编辑,条目随时可能增加,建议直接看英文。

如下的内容不完全翻译原文,穿插了一些自己的修改。

1. for i in $(ls *.mp3)

bash编程中最常见的错误之一就是把循环写出如下样子:

1
2
3
4
5
6
7
8
9
for i in $(ls *.mp3); do    # Wrong!
   some command $i          # Wrong!
done
for i in $(ls)              # Wrong!
for i in `ls`               # Wrong!
for i in $(find . -type f)  # Wrong!
for i in `find . -type f`   # Wrong!

(more…)

2014-09-02

ganglia/nagios集成

Filed under: 技术话题 — hunter @ 5:24 pm

1. 用了自带的python client

优点是可以比较精细获取某个指标 ,比如我用这个来判断没有外网IP的机器是否存活:

#!/bin/sh

if [ $# -lt 1 ];then
echo “USAGE: $0 [host]”
exit
fi

retmsg=`/opt/ganglia/bin/ganglia –host=${gmond_ip} –port=${gmond_port}  –alive=$1 |grep True`
if [ -z $retmsg ];
then
echo “CRITICAL: host:” $1 ” is dead!”
exit 2
else
echo “OK:host:” $1 ” is alive”
exit 0
fi
2. 用了ganglia-nagios-bridge

优点是可以批量获取、设置多个指标

安装过程遇到的错误

Filed under: 技术话题 — hunter @ 4:28 pm

1. ganglia python client运行错误

error msg:’cannot connect to ganglia server (gmond) [xxx:yyy]

modify:  vi /opt/ganglia/lib/python/gmon/ganglia.py +412

sock.connect((self.svchost, int(self.svcport)))

^^^^^^^^^

2. nagios 监控出现It appears as though you do not have permission

参考:http://bbs.linuxtone.org/thread-4440-1-1.html

有可能是你的htpasswd里面的用户名不是nagiosadmin,修改 cgi.cfg中相关配置即可

3. contact notification_options里面去掉 u 参数(unkown)

如: service_notification_options    w,c,r,f,s

因为ganglia的python插件会用unkown状态

« Newer PostsOlder Posts »

Powered by WordPress