不可轻言放弃,否则对不起自己!

发布新日志

  • 使用shell脚本实现自动SSH互信功能(转)

    2015-09-22 14:17:01

     说假设有一个1000台节点的Hadoop集群,要配置节点之间的SSH免密码登录,该如何用shell脚本实现?

    #!/bin/expect
     
    #循环1000台机器的IP地址,生成密钥文件authorized_keys
     
    for ip in {cat ip.list}
    do
        ssh user@$ip ssh-keygen -t rsa  &>/dev/null
        expect{
                    "yes/no" { send "yes\r";exp_continue}
                    "password:"{send "$passwd\r";exp_continue}
                  }
        cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys &> /dev/null  
        exit
        if [ !-f ~/.ssh/authorized_keys ];<br>    then
           touch ~/.ssh/authorized_keys<br>    fi
        ssh user@$ip cat ~/.ssh/authorized_keys >> ~/.ssh/authorized_keys  &> /dev/null
        expect{
                    "yes/no" { send "yes\r";exp_continue}
                    "password:"{send "$passwd\r";exp_continue}
                  }   
    done
     
    #scp authorized_keys 文件到各台机器上面。
    for ip in {cat ip.list}
    do
       scp ~/.ssh/authorized_keys user@$ip:~/.ssh/ 
        expect{
                    "yes/no" { send "yes\r";exp_continue}
                    "password:"{send "$passwd\r";exp_continue}
                  }  
    done


    原文地址:http://www.cnblogs.com/vovlie/archive/2012/10/17/2727029.html
  • 删除文件中的空格

    2014-06-06 10:37:14

    #!/usr/bin/bask

    ls|while read i;do  

        mv "$i" $(echo $i|tr -d ' ') 2>/dev/null  

    done 

  • 文件列求和

    2014-01-21 16:40:51

    对文件中某一列进行数值求和
     
    198 MMSGSUSE11 [wyz] :/home/wyz/perl/testcase>more tmp.txt
    testAddCountryCode.AddCountryCode 5 0 0 796.28
    testChcekSAGipNormal.ChcekSAGIPNormalTest 3 0 0 418.28
    testCheckInfoNormal.CheckInfoNormalTest 3 0 0 748.26
    testCheckSAGIPNormal.StageInteractiveNormalTest 3 0 0 804.79
    testCheckSPinfo.CheckSPinfoTest 12 0 0 1736.24
    testConsumModify.ConsumModify 8 0 0 2628.19
    testCountryCodeAbnormalCase.CountryCodeAbnormalTest 3 0 0 899.41
    testDelCountryCode.DelCountryCodeTest 5 0 0 1512.43
    testEmigratedInteractive.EmigratedInteractiveTest 1 0 0 401.68
    testGeneralOndemand.OndemandTest 10 0 0 2835.79
    testGeneralOndemandAbnormal.OnDemandAbnormal 4 0 0 1029.27
    testGiveOndemandAbnormal.GiveOndemandAbnormal 2 0 0 115.75
     
     
    操作:
    200 MMSGSUSE11 [wyz] :/home/wyz/perl/testcase>awk '{m+=$2} END{print m}' tmp.txt
    59
     
     
    对多列求和
    201 MMSGSUSE11 [wyz] :/home/wyz/perl/testcase>more t.txt
    00|M00a|0A|a00|0.00|15.00
    00|M00a|0A|a00|0.00|15.00
    00|M0Z1|0B|my|10.00|0.00
    00|M0Z1|0A|a00|10.00|0.00
    00|M005|0A|a00|0.00|1.48
    00|M005|0A|a00|2.96|0.00
    00|M005|0A|a00|2.96|0.00
    202 MMSGSUSE11 [wyz] :/home/wyz/perl/testcase>awk -F '|' '{m+=$5;n+=$6} END {print m,n}' t.txt
    25.92 31.48
     
  • linux wc命令详解

    2011-06-02 14:18:07

    1.作用:wc命令的可以统计指定文件中的字节数、字数、行数, 并将统计结果显示输出。

    2.用法:wc [选项]… [文件]…

    3.选项:

    -c, –bytes 统计字节数
    -m, –chars 统计字符数
    -l, –lines 统计行数
    -L, –max-line-length 输出最长的行的字符数
    -w, –words 统计字数

    不带选项时默认使用-lcw

    4.例子:

    grep 192.168.56.1 /var/log/httpd/access_log | wc -l 搜索Apache日志文件并统计来自192.168.56.1ip的访问量

    wc if.sh 单个文件
    15 80 365 if.sh 其中15为行数,80为字数,365为字节数

    wc /etc/httpd/conf.d/* 列出各个文件的技术以及所有文件的总计数

    5.注意事项:
    a:一个汉字占三个字节,一个回车符等不可见字符也占一个字节
    b:一行的末尾如果没有回车符,则不算是一行,也就是说,如果一个文件的最后一行末尾没有换行符,wc命令统计的行数会比实际行数少一,所谓实际行数是你所看到的行数,实际上,没有回车符,确实不能算作一行
    c:所谓一个字就是连续的字符,即不被空字符分割的连续的字母或者汉字算作是一个字

    获取文件大小
    wc -c setup_systemparameter | cut -c0-8 | sed 's/ //g'

  • gather.sh-2

    2011-06-02 09:35:32

  • gather.sh

    2011-06-02 09:33:28

  • run.sh

    2011-06-02 09:27:52

  • pid.sh

    2011-06-02 09:27:28

Open Toolbar