2014-09-11
bash flock
bash执行命令各种情况分析
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
bash 里的定时器
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编程陷阱一
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!donefor i in $(ls) # Wrong!for i in `ls` # Wrong!for i in $(find . -type f) # Wrong!for i in `find . -type f` # Wrong! |
2014-09-02
ganglia/nagios集成
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
优点是可以批量获取、设置多个指标