Warning: Undefined array key "cperpage" in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 255

Warning: Undefined variable $output in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 325

Warning: Undefined variable $fixed_tags in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 326

Warning: Undefined variable $isshowdots in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 327

Warning: Undefined variable $tag_aditional in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 330

Warning: Undefined variable $tag_aditional in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 333

Warning: Undefined variable $tag_aditional in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 336

Warning: Undefined variable $post in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 345

Warning: Attempt to read property "ID" on null in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 345

Warning: Undefined variable $post in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 345

Warning: Attempt to read property "ID" on null in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 345

Warning: Undefined variable $more_text_link in /www/wwwroot/www.now163.com/wp-content/themes/twentytwentyfive/functions.php on line 345
Shell – 理想社会

标签: Shell

  • 特殊的shell变量

    特殊的shell变量:

    $0 获取当前执行的shell脚本的文件名
    $n 获取当前执行的shell脚本的第n个参数值,n=1..9
    $* 获取当前shell的所有参数 “$1 $2 $3 …注意与$#的区别
    $# 获取当前shell命令行中参数的总个数
    $$ 获取当前shell的进程号(PID)
    $! 执行上一个指令的PID
    $? 获取执行的上一个指令的返回值(0 为成功, 非零为失败)
    $@ 这个程序的所有参数 “$1″ “$2″ “$3″ “…” (更多…)

  • 《SED单行脚本快速参考》的awk实现

    sed和awk都是linux下常用的流编辑器,他们各有各的特色,本文并不是要做什么对比,而是权当好玩,把《SED单行脚本快速参考》这文章,用awk做了一遍~
    至于孰好孰坏,那真是很难评论了。一般来说,sed的命令会更短小一些,同时也更难读懂;而awk稍微长点,但是if、while这样的,逻辑性比较强,更加像“程序”。到底喜欢用哪个,就让各位看官自己决定吧!
    PS: 貌似这个配色,单行的代码多了以后,拖动的时候会有点眼花的感觉,将就下吧,呵呵。

    文本间隔:
    ——–

    # 在每一行后面增加一空行

    sed G
    awk '{printf("%snn",$0)}'

    # 将原来的所有空行删除并在每一行后面增加一空行。
    # 这样在输出的文本中每一行后面将有且只有一空行。 (更多…)

  • 查看本服务器硬件信息(CPU、内存、硬盘等)

    以戴尔服务器为例:

    #!/bin/bash
    #查看服务器ip:
    ifconfig |grep -A7 “eth0” |grep “inet addr” |awk ‘{print $2}’|sed ‘s/addr://g’
    #查看服务器型号:
    dmidecode |grep -A8 “System Information” |grep “Product Name”|sed ‘s/^[ t]*//’
    #查看硬件编号:
    dmidecode |grep -A8 “System Information” |grep “Serial Number” |sed ‘s/^[ t]*//’
    #现有内容数量和容量:
    dmidecode |grep -A16 “Memory Device” |grep “Size” |sed ‘s/^[ t]*//’
    #最大支持内存容量:
    dmidecode |grep “Maximum Capacity” |sed ‘s/^[ t]*//’
    #查看CPU类型和主频:
    cat /proc/cpuinfo |grep “model name”
    #硬盘容量:
    fdisk -l |grep “Disk” |awk ‘{print $2$3$4}’

    (更多…)

  • shell脚本监控mysql服务器状态

    目的:
    1.监控mysql服务器的状态
    2.当发现mysql down机就自动重启mysql服务
    3.重启mysql不成功,发邮件给管理员警告mysql down机

    #vi /usr/local/sbin/sbin/check_mysql.sh
    (更多…)

  • awk计算某天是星期几

    unix 下的 cal 没有办法具体计算 哪天是星期几,写了个 awk 计算:

    echo "20110703" | awk '{ i=0; cald[0] = 0;
    mon = substr( $1, 5,2 )
    year = substr( $1, 1,4 )
    d = substr( $1, 7 )
    print $1
    while("cal"" "mon" "year | getline)
    {
    i++;
    if( i>2 )
    {
    for( j =1; j <=  NF;  j++ )
    {
    if( i == 3 )
    week = ( 7 - NF + j -1)
    else
    week = j == 1? 7: j-1
    cald[$j>=10?$j:"0"$j] = week
    }
    }
    }
    print cald[d]
    }'