免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: yuhongchun
打印 上一主题 下一主题

专家座谈——脚本分享与交流(大奖) [复制链接]

论坛徽章:
6
丑牛
日期:2013-09-17 00:18:40未羊
日期:2013-10-31 12:10:47午马
日期:2013-12-07 01:58:50水瓶座
日期:2013-12-24 22:43:12水瓶座
日期:2014-03-15 21:12:13操作系统版块每日发帖之星
日期:2016-08-07 06:20:00
31 [报告]
发表于 2011-09-14 19:05 |只看该作者
那我也斗胆来个吧
不排序排重1,打开含有ip的文件,每个ip地址一行
2,定义一个名叫ip的hash
3,从文件中 ...
wenzizone 发表于 2011-09-14 18:05


Perl的不多啊,希望蚊子兄再接再励,多发好文!!

论坛徽章:
1
CU十二周年纪念徽章
日期:2013-10-24 15:41:34
32 [报告]
发表于 2011-09-14 23:00 |只看该作者
打算看看python

论坛徽章:
0
33 [报告]
发表于 2011-09-14 23:17 |只看该作者
先晒一个入门级的脚下本吧,在通过cobbler批量布署centos后,各服务器的hostname、ip、mask、gateway、dns都 ...
king_819 发表于 2011-09-14 17:24



    代码最好放code段里,不然大家看着费劲……呵呵

论坛徽章:
0
34 [报告]
发表于 2011-09-15 09:37 |只看该作者
之前写的一个perl清除squid缓存的脚本

脚本设计思路:

1,遍历cache目录,拿到所有cache文件的名字
2,把cache文件内容和指定文件进行查找,取得对应的url地址
3,使用Net::HTTP模块模拟http请求purge掉对应的url

由于这个脚本使用了Net::HTTP模块,所以使用前,请先使用cpan安装此模块

脚本文件名:clear_cache.pl
  1. #! /bin/env perl

  2. use File::Find;
  3. use Net::HTTP;

  4. our @src_file_dir = ("/usr/local/squid/cache");
  5. our $grp_file = $ARGV[0];

  6. find(\&wanted, @src_file_dir);

  7. sub wanted {
  8.     !-d && search($File::Find::name);
  9. }

  10. sub search {
  11.     my $filename = shift;

  12.     open FH,"strings $filename |";

  13.     while(<FH>) {
  14.         chomp;
  15.         \&purge_cache($_) if (/$grp_file/i and /^http/);
  16.     }
  17. }

  18. sub purge_cache {
  19.     my $url = shift;
  20.     my $conn = Net::HTTP->new(Host => "127.0.0.1") or die $@;
  21.     $conn->write_request(PURGE => $url);
  22.     my($code, $mess, %h) = $conn->read_response_headers;
  23.     print $url,":",$code,"\n";
  24. }
复制代码
设置:
@src_file_dir= 设置squid缓存目录的路径

用法:
1、清除所有Flash缓存(扩展名.swf):
./clear_cache.pl swf

2、清除URL中包含wenzizone.cn的所有缓存:
./clear_cache.pl wenzizone.cn

论坛徽章:
0
35 [报告]
发表于 2011-09-15 09:40 |只看该作者
在来个shell的

用shell写了个递归遍历目录的脚本,本脚本实现递归遍历指定目录,打印目录下的文件名(全路径)。不为别的,就为了以后用着方便。
  1. #!/bin/sh

  2. function scandir() {
  3.     local cur_dir parent_dir workdir
  4.     workdir=$1
  5.     cd ${workdir}
  6.     if [ ${workdir} = "/" ]
  7.     then
  8.         cur_dir=""
  9.     else
  10.         cur_dir=$(pwd)
  11.     fi

  12.     for dirlist in $(ls ${cur_dir})
  13.     do
  14.         if test -d ${dirlist};then
  15.             cd ${dirlist}
  16.             scandir ${cur_dir}/${dirlist}
  17.             cd ..
  18.         else
  19.             echo ${cur_dir}/${dirlist}
  20.         fi
  21.     done
  22. }

  23. if test -d $1
  24. then
  25.     scandir $1
  26. elif test -f $1
  27. then
  28.     echo "you input a file but not a directory,pls reinput and try again"
  29.     exit 1
  30. else
  31.     echo "the Directory isn't exist which you input,pls input a new one!!"
  32.     exit 1
  33. fi
复制代码

论坛徽章:
0
36 [报告]
发表于 2011-09-15 10:24 |只看该作者
希望大家分享一些关于python的脚本!

论坛徽章:
0
37 [报告]
发表于 2011-09-15 10:51 |只看该作者
代码最好放code段里,不然大家看着费劲……呵呵
xiaopan3322 发表于 2011-09-14 23:17


抱歉,没注意,已修改!!

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
38 [报告]
发表于 2011-09-15 14:04 |只看该作者
啥时候成了senior moderator了?

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
39 [报告]
发表于 2011-09-15 14:09 |只看该作者
本帖最后由 expert1 于 2011-09-15 14:14 编辑

自动改密码
  1. #!/usr/bin/python
  2. # -*- coding=utf-8 -*-
  3. #  author : xiaofu68@live.cn
  4. # Usage: change user's password automatically.As usual,you want to change root's password, you may do it as the following:
  5. # 1.open terminal ,and then type "password root "
  6. # 2. type new password twice.
  7. #but run this chg_pwd_auto.py ,you just need to type "python chg_pwd_auto.py root "! Enjoy it!
  8. # Dont't forget to you have to install "pexpect" modules ,on Centos platform ,just run "yum -y install pexpect "

  9. import pexpect
  10. import sys
  11. import string
  12. import time
  13. from random import Random

  14. def genpwd():

  15.         pwdchars=string.letters + string.digits +'~!@#$%^&*-_=+?' # password seed ,change it yourself.
  16.         pwdlength=16
  17.         return ''.join(Random().sample(pwdchars, pwdlength))

  18. def changepwd(user,newpwd):

  19.         passwd=pexpect.spawn("passwd %s" % user)
  20.         passwd.logfile = sys.stdout
  21.         for repeat in xrange(2):

  22.                 passwd.expect("password: ")
  23.                 passwd.delaybeforesend = 0.07
  24.                 passwd.sendline(newpwd)
  25.                
  26.                 time.sleep(0.1)
  27. def main():
  28.         user=sys.argv[1]
  29.         newpwd=genpwd()
  30.         print "change password for %s" %user
  31.         print "newpwd:%s" % newpwd
  32.         changepwd(user,newpwd)

  33. if __name__ == "__main__":

  34.         main()
复制代码

论坛徽章:
4
CU大牛徽章
日期:2013-03-13 15:29:07CU大牛徽章
日期:2013-03-13 15:29:49CU大牛徽章
日期:2013-03-13 15:30:192015年迎新春徽章
日期:2015-03-04 09:57:09
40 [报告]
发表于 2011-09-15 15:16 |只看该作者
脚本好多,小弟不才啊,先占位。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP