linux下的一些小工具代码

python 代码正则提取文件

1 #! /usr/bin/env python
  2 # coding=utf-8
  3 
  4 import os
  5 import re
  6 import glob
  7 
  8 if __name__ == "__main__":
  9     rootdir = '../log'
 10     list = os.listdir(rootdir) #列出文件夹下所有的目录与文件
 11     for i in range(0,len(list)):
 12         path = os.path.join(rootdir,list[i])
 13         if os.path.isfile(path):
 14             for path in glob.glob("../log/mts_broker*"):#指定格式文件
 15                 #print path
 16                 file=open(path, "r")
 17                 content=file.read()
 18                 file.close()
 19 #    print "文件大小:",len(content)
 20                 m = re.findall("客户端发送的语音消息是:[\s\w]*?([^\w]*?)\s[^(发送)]*?返回给客户端的语音消息:\s[\w]*([^\s\w\x00\x0a]*)", content)
 21 #    print "大小 ",len(m)
 22                 for i in range(len(m)):
 23                     print m[i][0], "    ", m[i][1]

shell脚本 文本过滤

1 #!/bin/sh
  2 
  3 cd /opt/Charlene2.2.0RC1/logs#进入执行目录
  4 
  5 python jjktestpython.py | sort | uniq > test1
  6 
  7 grep -anr MRid /opt/Charlene2.2.0RC1/log/createMr.* | awk -F "MRid=|strRet="  -vOFS='\t' '{print $3,$2}' | sort | uniq > test2
  8 
  #两个文件建立关系 输出到一个文件中
  9 awk -vOFS='\t' 'NR==FNR{a[$2]=$1}NR>FNR{print a[$1],$0}' test1 test2

scp命令远程拷贝test.exp

#!/usr/bin/expect -f
spawn scp -rp /home/nico/git/game/MyProC galaxyeye@172.16.0.3:/opt/Charlene2.2.0RC1/src
set timeout 60 
expect "password:"
exec sleep 1
send "1\r"
interact

rsync远程拷贝命令 test.exp

#!/usr/bin/expect -f
spawn rsync -av -e rsh galaxyeye@172.16.0.3:/opt/Charlene2.2.0RC1/include galaxyeye@172.16.0.3:/opt/Charlene2.2.0RC1/lib /home/nico/
set timeout 60 
expect "password:"
exec sleep 1
send "1\r"
interact

自动登录脚本 login.exp

#!/usr/bin/expect -f
spawn ssh charlene@192.168.1.201
set timeout 60 
expect "Password:"
exec sleep 1
send "charlene\r"
exec sleep 1
expect "Last*"
send "PS1=201\$PS1\n"
interact

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值