script
cyan_grey
这个作者很懒,什么都没留下…
展开
-
python多线程端口探活
python脚本多线程探测指定网段中存活的主机,并探测指定端口是否开启#!/usr/bin/env pythonimport telnetlibimport threadingimport queueimport nmapdef get_ip_list(host_segment_list): ip_list = [] for host_segment in host_segment_list: nmScan = nmap.PortScanner()原创 2021-07-27 21:40:27 · 579 阅读 · 0 评论 -
python3从ES统计域名uri访问次数
数据从ELK拉取,因为ELK满足不了需求,写个脚本处理from elasticsearch import Elasticsearchimport sysfrom collections import Counterimport timeimport xlsxwriterimport openpyxlimport smtplibfrom email.mime.text import MIMETextfrom email.mime.image import MIMEImagefrom ema原创 2020-10-23 17:36:27 · 687 阅读 · 1 评论 -
python配合crontab自动发送邮件
很多时候需要实现自动邮件发送,例如每天的日志,告警或者其他审计信息。python脚本实现发送邮件,crontab定时任务实现定时自动发送。python脚本如下:#!/usr/bin/python#-*-coding:utf-8 -*-#import smtplibfrom email.mime.text import MIMETextfrom email.mime.image import MIMEImagefrom email.mime.multipart import MIMEMul原创 2020-06-15 20:24:53 · 485 阅读 · 0 评论 -
关于history命令
如果你经常使用 Linux 命令行,那么使用 history(历史)命令可以有效地提升你的效率。本文将通过实例的方式向你介绍 history 命令的 15 个用法。使用 HISTTIMEFORMAT 显示时间戳当你从命令行执行 history 命令后,通常只会显示已执行命令的序号和命令本身。如果你想要查看命令历史的时间戳,那么可以执行:# export HISTTIMEFORMAT...转载 2018-04-08 11:50:54 · 199 阅读 · 0 评论 -
linux日志审计audit
Linux内核有用日志记录事件的能力,比如记录系统调用和文件访问。然后,管理员可以评审这些日志,确定可能存在的安全裂口,比如失败的登录尝试,或者 用户对系统文件不成功的访问。这种功能称为Linux审计系统,在Red Hat Enterprise Linux 5中已经可用。 要使用Linux Auditing System,可采用下面的步骤: (1) 配置审计守护进程。 (2) 添...转载 2018-04-16 11:08:20 · 12448 阅读 · 0 评论 -
对目录权限的理解
问题描述:研究setfacl命令时,发现一个问题,即设置了一个文件的acl权限之后,这个权限仍不能生效。 例如,对/root/test文件做了setfacl -m u:user1:rwx /root/test之后,user1仍是不能访问文件test。 思考之后觉得是目录的问题,即user1对/root/目录没有权限,于是继续进行setfacl:setfacl -m u:user1:rw /ro...原创 2018-04-11 11:43:58 · 644 阅读 · 0 评论 -
shell脚本自动部署tomcat项目
自动部署shell脚本由4个方法组成: deploy_backup(版本备份)、deploy_unzip(自动解压新版本)、deploy_restart(重启tomcat)、deploy_Rollback(版本回滚),当然,每个方法可以独立执行,此处在开始运行脚本时给出了2个选择,0:版本回滚,其他任意输入会自动部署新的版本包并重启tomcat。shell脚本代码如下:#!/bin/bash ...转载 2018-05-04 16:52:45 · 2739 阅读 · 0 评论 -
Linux shell脚本013(生成配置文件)
#!/bin/bash#生成配置文件auto-ops.conf的中间件配置项,要求auto-ops.conf文件已经存在###参数规范性校验###清除原有中间件的参数配置CONFIG=auto-ops.confif [ -f ${CONFIG} ]; then sed -i '/\"jboss\"/,$d' auto-ops.conf ...原创 2018-06-14 16:56:45 · 1463 阅读 · 0 评论 -
检测本机所有ip所在网段内的可ping主机
逻辑如下所述:先获取本机所有ip除去回环地址判断ip的掩码,根据掩码位数,分别使用for循环进行ping测试。24位掩码一层for循环,16位掩码2层for循环,8位掩码3层for循环,0位掩码无循环使用并发运行ping命令,同时使用命名管道和文件描述符控制并发数,另外涉及到,同时有两个变量的for循环脚本如下:#!/bin/bash########################...原创 2018-12-12 15:38:04 · 3627 阅读 · 0 评论 -
1.py(备份指定目录的指定日期之前的文件)
#!/usr/bin/env python# -*- coding: UTF-8 -*-##################################################################Describe:查找path1目录中N天之前的文件并备份到path2目录#Date:2018-12-17#Usage:1.py path1 path2 days###...原创 2018-12-18 10:28:17 · 424 阅读 · 0 评论 -
2.py(创建随机命名的文件)
#!/usr/bin/env python# -*- coding: UTF-8 -*-########################################Describe:生成随机字符串命名的文件#Date:2018-12-18#Usage:2.py file_count#file_count is the quantity of files##############...原创 2018-12-18 15:19:27 · 282 阅读 · 0 评论 -
Linux shell脚本012(数学运算)
算术运算符指的是可以在程序中实现加、减、乘、除等数学运算的运算符。Shell中常用的数学运算符如下所示。+:对两个变量做加法。–:对两个变量做减法。*:对两个变量做乘法。/:对两个变量做除法。**:对两个变量做幂运算。%:取模运算,第一个变量除以第二个变量求余数。+=:加等于,在自身基础上加第二个变量。-=:减等于,在第一个变量的基础上减去第二个变量。*=:乘等于,在第一个变...原创 2018-02-08 15:22:57 · 590 阅读 · 1 评论 -
Linux shell脚本004(批量创建用户)
#!/bin/bashUSER=cyanuser_add(){for i in {01..10}do PASSWORD=`tr -dc a-zA-Z0-9 < /dev/urandom | head -c8` useradd $USER$i > /dev/null echo $PASSWORD | passwd --stdin $USER$i > /dev/nu原创 2018-01-16 15:45:11 · 233 阅读 · 0 评论 -
Linux shell脚本009(文件锁、规范化运维脚本)
#!/bin/bashSHELL_NAME="shell_template_3.sh"SHELL_DIR="/root/test"SHELL_LOG="${SHELL_DIR}/${SHELL_NAME}.log"LOCK_FILE="/root/test/${SHELL_NAME}.lock"shell_log() { LOG_INFO=$1 ech转载 2018-01-19 14:11:25 · 451 阅读 · 0 评论 -
Linux shell脚本010(mysql操作脚本)
#!/bin/bashhost="localhost"user="root"passwd="Wck12345"db="testdb"table="test"log="/root/test/log_sql"sql_create_db="create database IF NOT EXISTS ${db}"sql_create_table="create table IF NOT E原创 2018-01-25 14:29:58 · 275 阅读 · 0 评论 -
Linux shell脚本008(四则计算器select语句)
#!/bin/bashoperators="+ - X / exit"echo 'please inpunt num1:'read num1echo 'please input num2'read num2echo 'select a operator:'select o in $operatorsdo case $o in +) e原创 2018-01-19 11:33:35 · 589 阅读 · 0 评论 -
Linux shell脚本007(select菜单选项)
#!/bin/bashnames=( "张三" "李四" "王二")echo "Please guess who is my friend :"select var in ${names[@]}do if [ x$var = x"李四" ]; then #这里$var和"apple"前边的x,,是为了避免,当原创 2018-01-19 09:53:32 · 1293 阅读 · 0 评论 -
Linux shell脚本006(移动超大文件)
(1)#!/bin/bash for FileName in `ls -l /usr/local/test | awk '$5>102400' | awk '{print $9}'` do mv $FileName /tmp/ done ls -al /tmp/ echo "done!"(2)#!/bin/bashecho "i原创 2018-01-18 21:56:52 · 719 阅读 · 0 评论 -
Linux shell脚本005(并发执行检测在线主机)
#!/bin/bashtrap "exec 1000>&-;exec 1000<&-;exit 0" 2mkfifo testfifoexec 1000<>testfiform -fr testfifofor ((n=1;n<=254;n++)) #可修改n的值,以减小并发量do echo >&1000don...原创 2018-01-17 13:51:11 · 566 阅读 · 0 评论 -
Linux shell 脚本001(备份五天之前的文件)
#!/bin/bashNOW=$(date +%Y%m%d)touch /tmp/$NOW"_"backup #最好随机命名,以免与原有文件的名字冲突touch /home/logs/$NOW >/dev/nullfind $(pwd) -mtime +5 | egrep -v "^$|$0" >> /home/logs/$NOWfind $(pwd) -mtime +5 | awk原创 2018-01-16 09:49:11 · 1588 阅读 · 0 评论 -
Linux shell 脚本002(随机命名文件)
#!/bin/bashfor ((i=1;i5;i++));doRAN=`tr -dc a-z </dev/urandom | head -c5`touch $RAN"_"cyan.htmldone知识点: for循环,tr -dc用法,随机字符,head -c用法 创建随机字母命名的文件原创 2018-01-16 14:44:46 · 1143 阅读 · 0 评论 -
Linux shell脚本003(批量修改文件名后缀)
#!/bin/bashfunction change_name(){FILE=`ls $(pwd)`NAME=_grey.HTMLfor i in $FILEdo NA=`echo $i | cut -c 1-5` mv $(pwd)/$NA* $(pwd)/$NA$NAMEdone}change_name知识点: 变量拥有多个原创 2018-01-16 14:58:55 · 620 阅读 · 0 评论 -
Linux shell脚本011(centos7优化)
#!/bin/bash#this script is only for CentOS 7.xplatform=`uname -i`if [ $platform != "x86_64" ];then echo "脚本仅适合64位CentOS 7系统"exit 1fiecho "----------CentOS 7 64位系统,开始优化----------"#添加公网DNS地址c原创 2018-01-30 17:00:23 · 898 阅读 · 0 评论