Blog

  • linux使用inode笔记

    今天使用ansible生成文件时,提示目标文件有 hard 硬链接,执行失败。

    想要查到到底有哪些硬链,那么可以找到这些文件

    find . -type f -links +1

    要找到文件的inode, 使用 ls -li, 显示如下,第一列为inode number

    6160399 -rw-r--r--. 3 root root 72 5月 6 2014 ifcfg-eth0

    再找到都有哪些文件硬链到这个文件,使用find命令

    find / -follow -inum 6160399

    另一个例子,有时候shell下会生成一些乱码或touch ‘~’,这样删除挺麻烦的,即然是文件就有inode number,结合上面的命令,先找到inode number

    rm `find . -follow -inum 1192387`
  • 查看系统的内存

    查看cpu个数,核心数,型号,频率

    实际cpu个数:  cat /proc/cpuinfo | grep ‘physical id’ | uniq -c
    4 physical id     : 0       4 physical id     : 1       4 physical id     : 0       4 physical id     : 1

    实际cpu核心数及型号频率

    [root@puppet124 ~]# cat /proc/cpuinfo | grep name | cut -d: -f2 | uniq -c      16  Intel(R) Xeon(R) CPU           L5520  @ 2.27GHz

    查看内存条数及大小

    dmidecode | grep -P -A 5 “Memory Device” | grep Size | grep -v Range | grep -v No

    查看物理网卡及MAC地址

    ifconfig -a | grep HWaddr | awk ‘{print $5}’

    查看网卡支持的速度及当前工作的状态

    # ethtool eth0
    
    脚本:
    cpu and Mem:
    
    cpu物理个数
    
    physical cpu count: `cat /proc/cpuinfo | grep 'physical id' | uniq -c | wc -l`
    
    cpu核心个数型号频率
    
    processor core count: `cat /proc/cpuinfo | grep name | cut -d: -f2 | uniq -c | awk '{print $1}'`
    processor model: `cat /proc/cpuinfo | grep name | cut -d':' -f 2 | uniq`
    
    memory sock count:`dmidecode | grep -P -A 5 "Memory Device" | grep Size | grep -v Range`
    total memory:`dmidecode | grep -P -A 5 "Memory Device" | grep "Range Size"`
    
    查看序列号:
    
    dmidecode -s system-serial-number
    
    
  • 经典爱情句子

    经典爱情句子
    1) I love you not because of who you are, but because of who I am when I am with you.
    我爱你,不是因为你是一个怎样的人,而是因为我喜欢与你在一起时的感觉。

    2) No man or woman is worth your tears, and the one who is, won‘t make you cry.
    没有人值得你流泪,值得让你这么做的人不会让你哭泣。

    3) The worst way to miss someone is to be sitting right beside them knowing you can‘t have them.
    失去某人,最糟糕的莫过于,他近在身旁,却犹如远在天边。

    4) Never frown, even when you are sad, because you never know who is falling in love with your smile.
    纵然伤心,也不要愁眉不展,因为你不知是谁会爱上你的笑容。

    5) To the world you may be one person, but to one person you may be the world.
    对于世界而言,你是一个人;但是对于某个人,你是他的整个世界。

    6) Don‘t waste your time on a man/woman, who isn‘t willing to waste their time on you.
    不要为那些不愿在你身上花费时间的人而浪费你的时间。

    7) Just because someone doesn‘t love you the way you want them to, doesn‘t mean they don‘t love you with all they have.
    爱你的人如果没有按你所希望的方式来爱你,那并不代表他们没有全心全意地爱你。

    8) Don‘t try so hard, the best things come when you least expect them to.
    不要着急,最好的总会在最不经意的时候出现。

    9) Maybe God wants us to meet a few wrong people before meeting the right one, so that when we finally meet the person, we will know how to be grateful.
    在遇到梦中人之前,上天也许会安排我们先遇到别的人;在我们终于遇见心仪的人时,便应当心存感激。

    10) Don‘t cry because it is over, smile because it happened.
    不要因为结束而哭泣,微笑吧,为你的曾经拥有。

    11).Life is a pure flame,and we live by an invisible sun within us.
    生命是一束纯净的火焰,我们依靠自己内心看不见的太阳而存在。

    12).Make yourself a better person and know who you are before you try and know someone else and expect them to know you.
    在你尝试了解他人和盼望他人了解你之前,先把你变成一个更好的人和了解自己的人。

    13).Atrue friend is some one who reaches for your hand and touches your heart.
    一个真正的朋友是向你伸出手,触动你心灵的人。

  • ansible jinja2模板使用

    在j2中可以很方便的使用 ansible setup 模块中的变量

    如以下是一个bind的配置文件

      {% if ansible_bond0.ipv4.address %}
      bind {{ ansible_bond0.ipv4.address }}
      {% elif ansible_eth0.ipv4.address %}
      bind {{ ansible_eth0.ipv4.address }}
      {% else %}
      bind 0.0.0.0
      {% endif %}
    

    以下是一个snmp磁盘分区的设定

    {% for i in ansible_mounts %}
    {% if i['mount']  != '/boot' %}
    disk {{ i['mount'] }} 10% 
    {% endif %}
    {% endfor %}
  • 从事IT最重要的是什么

    最近一直在思考这个问题,因为从我第一次上网开始,接触互联网已经10年了。

    做IT什么是最重要的

    以前花很多时间在硬件设备,挂QQ,下片子,下mp3,注册邮箱,注册域名,折腾虚拟主机,装系统,写小脚本,配vpn…

    回想起来很傻X,一直在折腾IT的外围的东西,设备域名用什么软件根本不是那么重要。最后也没搞出什么名堂来。

    现在在做运维的职业和一些开发工作,本身也是很外围的东西,为开发和业务服务。遇到运维问题之后打算做点东西,首先需要有编程的知识,然后想尽办法做一个别人会用的到东西。

    需要长时间的学习,才能渐渐接进互联网最重要的 — 产品和业务。

    在互联网做事的方法上,快速迭代验证想法十分重要,一个自认为很好的想法只有在快速迭代的验证下才变得有意义。只有小的想法都难证过了,才会找到最真实客观,而又简单美丽的东西。

    那么除了工作,我的人生什么是最重要的

    罗素说过:三种简单而又极度强烈的情感支配着我的一生:对爱情的渴望、对知识的追求和对人类苦难的深切同情。

    追求感情,追求知识,追求能有一份事业,人不能浪费自己的时间,心有多宽,能做的事,能获取的知识就有多宽,幸福就有多满。当前我还处于很低的位置,因为我有很多问题无法克服,物质困扰着我,自信不够强烈,求知不够耐心,不够虚心,工作不够专心,急功近利。应无视这些阻力和恐惧,始终保持自己无知的态度,容纳更多知识及涵养,到达每一个阶段都当做新的起点。追求人性和自然的本源。

  • python print颜色

    定义一个class

    class bcolors:
        HEADER = '\033[95m'           # 粉色
        OKBLUE = '\033[94m'           # 蓝色
        OKGREEN = '\033[92m'          # 绿色
        WARNING = '\033[93m'          # 黄色
        FAIL = '\033[91m'             # 红色
        BOLD = '\033[1m'              # 粗体
        ENDC = '\033[0m'              # 结束
    

    不管显示哪种颜色,最后都需要用end结束,不然会一直渲染。

    print bcolors.WARNING + "Warning: No active frommets remain. Continue?" + bcolors.ENDC

    参考:
    http://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python

    其他颜色可以参考

    #!/usr/bin/perl
    print "0\t\033[0m coloured! \033[m\n";
    print "1\t\033[1m coloured! \033[m\n";
    print "4\t\033[4m coloured! \033[m\n";
    print "7\t\033[7m coloured! \033[m\n";
    print "31\t\033[31m coloured! \033[m\n";
    print "32\t\033[32m coloured! \033[m\n";
    print "33\t\033[33m coloured! \033[m\n";
    print "34\t\033[34m coloured! \033[m\n";
    print "35\t\033[35m coloured! \033[m\n";
    print "36\t\033[36m coloured! \033[m\n";
    print "37\t\033[37m coloured! \033[m\n";
    print "38\t\033[38m coloured! \033[m\n";
    print "39\t\033[39m coloured! \033[m\n";
    print "40\t\033[40m coloured! \033[m\n";
    print "41\t\033[41m coloured! \033[m\n";
    print "42\t\033[42m coloured! \033[m\n";
    print "43\t\033[43m coloured! \033[m\n";
    print "44\t\033[44m coloured! \033[m\n";
    print "45\t\033[45m coloured! \033[m\n";
    print "46\t\033[46m coloured! \033[m\n";
    print "47\t\033[47m coloured! \033[m\n";
    print "90\t\033[90m coloured! \033[m\n";
    print "91\t\033[91m coloured! \033[m\n";
    print "92\t\033[92m coloured! \033[m\n";
    print "93\t\033[93m coloured! \033[m\n";
    print "94\t\033[94m coloured! \033[m\n";
    print "95\t\033[95m coloured! \033[m\n";
    print "96\t\033[96m coloured! \033[m\n";
    print "97\t\033[97m coloured! \033[m\n";
    print "98\t\033[98m coloured! \033[m\n";
    print "99\t\033[99m coloured! \033[m\n";
    print "100\t\033[100m coloured! \033[m\n";
    print "101\t\033[101m coloured! \033[m\n";
    print "102\t\033[102m coloured! \033[m\n";
    print "103\t\033[103m coloured! \033[m\n";
    print "104\t\033[104m coloured! \033[m\n";
    print "105\t\033[105m coloured! \033[m\n";
    print "106\t\033[106m coloured! \033[m\n";
    print "107\t\033[107m coloured! \033[m\n";
    print "108\t\033[108m coloured! \033[m\n";