Author: jpuyy

  • paste命令

    要把

    a
    b
    c
    d
    e

    变成

    a b c d e

    使用 paste 命令

    paste -s -d' ' filename

    paste 可以将多个文件整合,按列整合

    文件1  file1

    a

    b

    文件2 file2

    1

    2

      ~ paste file1 file2

    a 1

    b 2

      ~ paste -d’ ‘ file1 file2

    a 1

    b 2

    也可以变成

      ~ paste -s file1 file2

    a b

    1 2

    如果想把 奇偶行 拼接成一行,文件为

    1 foo
    2 bar
    3 foo
    4 bar
    5 foo
    6 bar
    7 foo
    8 bar
    

    命令为

    cat filename | paste -d, - -
    1 foo,2 bar
    3 foo,4 bar
    5 foo,6 bar
    7 foo,8 bar

    如果把三行并成一行

    cat filename | paste -d, - - -
  • 配置rsync服务

    要求:配置针对单一ip的免认证 rsync 服务,环境为 centos 6.5,需要关闭 SELINUX

    安装

    yum install -y xinetd rsync

    检查 iptables 需要使 873 端口通行

    配置 xinetd

    vim /etc/xinetd.d/rsync
    # default: off
    # description: The rsync server is a good addition to an ftp server, as it \
    #	allows crc checksumming etc.
    service rsync
    {
    	disable	= no
    	flags		= IPv4
    	socket_type     = stream
    	wait            = no
    	user            = root
    	server          = /usr/bin/rsync
    	server_args     = --daemon
    	log_on_failure  += USERID
    }
    

    配置 rsync 配置文件

    vim /etc/rsyncd.conf
    max connections = 5
    log file = /var/log/rsync.log
    uid = nobody
    gid = nobody
    [web]
    path = /home/ftpuser1
    read only = false
    hosts allow = 192.168.1.1
    

    重启 xinetd

    上面访问的路径就为 rsync -av 192.168.x.x::web .

    参考:

    Setup Rsync in 5 Minutes – Centos 6

    如果不使用 xinetd 来做守护。创建如下目录和文件

    /etc/rsyncd

    ├── rsyncd.conf

    └── rsyncd.secrets

    查看 rsyncd.conf

    pid file = /var/run/rsyncd.pid
    port = 873
    address = 192.168.1.123
    uid = root
    gid = root
    use chroot = yes
    read only = no
    hosts allow=192.168.1.0/255.255.255.0
    hosts deny=*
    max connections = 10
    motd file = /etc/rsyncd/rsyncd.motd
    log format = %t %a %m %f %b
    syslog facility = local3
    timeout = 300
    [bbs]
    path = /data/www/bbs
    list=yes
    ignore errors
    auth users = my_name
    secrets file = /etc/rsyncd/rsyncd.secrets
    comment = blog
    

    查看 rsyncd.secrets

    my_name:mypass

    之后要想传文件到 192.168.1.123 的 /data/www/bbs 下

    客户端创建文件 /etc/sersync/rsync_password
    写入
    mypass
    权限为 0400

    执行

    rsync -a -R --delete ./ --include=bbbb --exclude=* [email protected]::bbs --password-file=/etc/sersync/rsync_password

    关于权限问题而不成功参考:
    http://superuser.com/questions/243656/how-to-configure-and-use-rsyncd

    rsyncd 的 init 文件

    #! /bin/bash
    #
    # chkconfig:   2345 50 50
    # description: The rsync daemon
    #pidfile: /var/run/rsyncd.pid
    
    # source function library
     . /etc/rc.d/init.d/functions
    
    PROG='/usr/bin/rsync'
    BASE=${0##*/}
    
    # The config file must contain following line:
    #  pid file = /var/run/rsync.pid
    OPTIONS="--daemon --config=/etc/rsyncd/rsyncd.conf"
    
    case "$1" in
      start)
        echo -n $"Starting $BASE: "
        daemon $PROG $OPTIONS
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASE
        echo
        ;;
      stop)
        echo -n $"Shutting down $BASE: "
        killproc $PROG
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BASE
        echo
        ;;
      restart|force-reload)
        $0 stop
        sleep 1
        $0 start
        ;;
      status)
        status $PROG
        ;;
      *)
        echo "Usage: $0 {start|stop|restart|status|force-reload}" >&2
        exit 1
        ;;
    esac
    

     

  • mac dd 命令将制作 centos7 iso usb启动盘

    查看所有的 disk

    diskutil list
    /dev/disk1
     #: TYPE NAME SIZE IDENTIFIER
     0: FDisk_partition_scheme *7.7 GB disk1
     1: Windows_NTFS 未命名 7.7 GB disk1s1

    解除其挂载

    diskutil unmountDisk /dev/disk2

    用 dd 命令将 iso 写入

    sudo dd if=/Users/jpuyy/Downloads/CentOS-7.0-1406-x86_64-Minimal.iso of=/dev/disk2 bs=1m
  • python ftp测试脚本

    配置 vsftp ,用 python 测试 ftp 很方便

     

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    #author: jpuyy.com date
    #modified by xx at date
    
    from ftplib import FTP
    
    def ftp_list(file = "group_xitong"):
        ftp=FTP()
        ftp.set_debuglevel(2)                                                                                                       
        #ftp.connect('106.186.23.161','21')
        ftp.connect('119.28.3.73','4413')
        ftp.login('ftpuser1','QAXjAHd7pAziK8')
        print ftp.getwelcome()
        ftp.cwd('/')
        ftp.retrlines('LIST')
        ftp.quit()
    
    ftp_list()
    
  • arping

    arping 192.168.1.100 可 ping 出当前 ip 对应的 mac 地址。

  • debian忘记密码

    下面介绍一个在所有版本linux的grub上均可以使用的方法:
    1、在Grub的引导装载程序菜单上,选择你要进入的条目,键入 “e” 来进入编辑模式。
    2、在第二行(类似于kernel /vmlinuz-2.6.15 ro root=/dev/hda2 ),键入”e”进入编辑模式;
    3、在句末加上”init=/bin/bash”,回车;
    4、按“b”启动系统。
    这样我们即可获得一个bash的shell。
    进入shell后,根分区的挂载模式默认是只读,我们要将其改为可写,否则不能更改root密码:

    mount -no remount,rw /
    passwd root
    sync
    mount -no remount,ro /
    reboot