您正在查看: 标签 bash 下的文章

bash snippets

Little Useful Functions

The Real Dir of Script itsef

sometimes we need to change dir to the real path of a script and do something. But this little thing is very hard to make it works in lots of Linux Distribution and Mac OS X. The snippets below is work on CentOS, Ubuntu and Mac OS X 10.10.

#!/bin/sh
# read link 
_script="$(readlink -n ${0})"
if [[ $_script = '' ]]; then
    # when call script without symbolic, readlink will return empty string
    pushd `dirname $0` > /dev/null
    _script=`pwd`
    popd > /dev/null
else
    _script="$(dirname $_script)"
fi
echo 'the real path is ' $_script

command usage

echo color

16color syntax:

# \033 is the Escape symbol in ASCII, it can also written in \x1b
echo -e "\033[${attr};${clbg};${clfg}m${renderText}\033[0m"
# -e explain as use string escape
# if you let \033[ in a variable, -e is not necessary. such as
start="\x1b["
end="\x1b[0m"
echo "${start}${attr};${clbg};${clfg}m${renderText}${end}"

which attr is control number, clbg is background color, clfg is foreground color.
The detail is in tip_colors_and_formatting

hadoop自动安装的脚本与步骤

最近要在10几台机器上安装hadoop。对于这种繁复而重复的工作,一步步的打命令行,对于程序员来说是一件不能忍的事情。所以我就琢磨着怎么写一个脚本来自动安装hadoop。

任务: 在10几台机器上中的任意一台执行脚本,即可安装好hadoop。

条件: 每台机器的用户名和密码都是一样的。每台机器都配置好了ssh,能够远程登录。

Continue Reading...