不看后悔的Linux生产服务器Shell脚本分享

摘要:                                                          &n

 通过创建DNS脚本一步一步教你将一个普通脚本规范到一个生产环境脚本

摘要:通过脚本案例学习shell(五)通过创建DNS脚本一步一步教你将一个普通脚本规范到一个生产环境脚本 版权声明:本文遵循“署名非商业性使用相同方式共享 2.5 中国大陆”协议您可以自由复制、发行、展览、表演、放映、广播或通过信息网络传播本作品您可以根据本作品演义自己的作品您必须按照作者或者许可人指定的方式对作品进行署名。您不得将本作品用于商业目的。如果您改变、

 生产环境中安装vsftpd的shell脚本

摘要:生产环境中安装vsftpd的shell脚本:vi install_vsftpd.sh#!/bin/bash# Remove=>Download=>Install=>Configure=>Start service "vsftpd"## /usr/bin/yum => #!/usr/bin/python2.4# Remove old/sbin/service vsftpd stop/usr/bin/yum -y remove vsftpd db4-utils/bin/rm -rf /etc/vsftpd# Download and install new program/usr/bin/yum -y install vsf

 对线上服务进行监控,如果死掉,就立即重启,以httpd进程为例:

摘要:#/bin/bash# edit: www.jbxue.com#SLEEPTIME=30while truedo     id=`ps aux | grep httpd | grep -v "grep" | wc -l`     if [ $id -lt 1 ]; then         echo "---`date +"%F %H:%M:%S"`-----httpd restart." >> /u/scripts/httpd_monitor.log 

 检测SSH攻击,并报警

摘要:#!/bin/bash#edit: www.jbxue.com#Prevent SSH attack#SLEEPTIME=30lastb -n 500| grep -v "^$" | grep -v "btmp" | awk '{print $3}' | sort | uniq -c  | grep -v "公司IP" |sort -nr > attack.logwhile truedo     while read line     do        

 系统初始化SHELL脚本

摘要:此脚本用于新装CentOS的相关配置工作,比如禁掉iptable和SElinux及ipv6,优化系统内核,停掉一些没必要启动的系统服务等。此脚本尤其适全大批新安装的CentOS 5.X系列的服务器,脚本代码如下所示(此脚本在Centos5.5_x64下已通过): #!/bin/bash # Created by kerryhu # MAIL:king_819@163.com # BLOG:http://kerry.blog.51cto.com cat << EOF +-------------------

 用SHELL脚本来防SSH和vsftpd暴力破解(第②版)

摘要:新近刚上的FTP备份服务器,例行检查/var/log/secure日志时,发现不少sshd和vsftpd失败认证信息,很明显有人想用暴力破解工具窃取密码,所以需要编写一个安全脚本防止。脚本需求如下:此SHELL脚本放在crontab计划任务里,每隔6小时(此时间根据实际情况来定义)就去读取/var/log/secure脚本,取出里面恶意猜测IP,如果单位时间内(一星期)的连接数是高于一个阀值,例如100(此阀

 用SHELL脚本自动化安装Nagios服务器端和客户端的

摘要:公司的一个项目网站,上线几天就因为磁盘暴满而出了问题,由于其服务器都集中在某一IDC机房内,所以考虑部署套Nagios监控报警系统,考虑到其它项目网站可能有类似需求,所以将其安装过程整理成脚本,方便以后的工作。Nagios服务器自动安装脚本,如下所示(此脚本在Centos5.5|5.6|5.8 x86_64下通过):12345678910111213141516171819202122232425262728293031323334353637383940

 shell采集系统cpu 内存 磁盘 网络信息

摘要:cpu信息采集--------------------------------------------------------------------------------cpu使用率采集算法通过/proc/stat文件采集并计算CPU总使用率或者单个核使用率。以cpu0为例,算法如下:1. cat /proc/stat | grep ‘cpu0’得到cpu0的信息2. cpuTotal1=user+nice+system+idle+iowait+irq+softirq3. cpuUsed1=user+nice+system+irq+softirq4. sleep 30秒5. 再次cat

 shell脚本制作俄罗斯方块游戏

摘要:#!/bin/bash# Tetris Game# 10.21.2003 xhchen<[email]xhchen@winbond.com.tw[/email]>#APP declarationAPP_NAME="${0##*[\\/]}"APP_VERSION="1.0" #颜色定义cRed=1cGreen=2cYellow=3cBlue=4cFuchsia=5cCyan=6cWhite=7colorTable=($cRed $cGreen $cYellow $cBlue $cFuchsia $cCyan $cWhite)#位置和大小iLeft=3iTop=2((iTrayLeft = iLeft + 2))(

 shell脚本通过日志来统计网站pv 404 500状态码

摘要:下面的脚本能统计出网站的总访问量,以及404,500出现的次数。统计出来后,我们可以结合监控宝来进行记录,进而可以看出网站访问量是否异常,是否存在攻击,一目了然。还可以根据查看500出现的次数,进而判断网站程序是否出现异常。#!/bin/bash#purpose:count nginx or apache or other webserver status code using jiankongbao#how to:run the script every 5 minutes with cr

 tar命令批量解压方法总结

摘要:由于linux的tar命令不支持批量解压,所以很多网友编写了好多支持批量解压的shell命令,收集了一下,供大家分享:第一:for tar in *.tar.gz;  do tar xvf $tar; donefor tar in *.tar.bz2; do tar xvf $tar; done#!/bin/bashfor tar in *.tar.gzdo        tar xvf $tardone第二:用tar命令批量解压某个文件夹下所有的tar.gz文件l

 批量删除用户

摘要:#!/bin/bashecho "Please input username:"read nameecho "Please input number:"read numsum=0while [ $sum -lt $num   ]dosum=`expr $sum + 1`/usr/sbin/userdel -r $name$sumdone        

 批量添加用户

摘要:#!/bin/bash#The script to add user#The script to add user#/etc/passwd infoecho "please input username:"read nameecho "please input number:"read numn=1while [ $n -le $num     ]do        /usr/sbin/useradd $name$n        n=`expr $n + 1`done#/e

 删除指定的登陆用户

摘要:#!/bin/bash#FileName killuser.sh#The script to kill logined user.#Using #/bin/bash killuser.sh rootusername="$1"/bin/ps aux | /bin/grep $username | /bin/awk '{ print $2 }' > /tmp/temp.pidkillid=`/bin/cat /tmp/temp.pid`for PID in $killiddo        /bin/kill -9 $PID 2 > /dev/nulldone  

 测试文件类型if...else

摘要:#!/bin/bash  #filename=detect_file_type                                                   

 测试web服务器是否停止

摘要:#!/bin/bash#"if...else" usage#FileName test.apache#Using this program to show your system's services.echo "Now,the web services of this Linux system will be detect..."echo #Detect www service web=`/usr/bin/pgrep httpd`if [    "$web" != ""    ]then     &nb

 自动备份命令autobak.sh

摘要:#/bin/bash#backup files by date#filename autobak.shDATE=`/bin/date +%Y%m%d`/bin/tar -cf /backup/$1.$DATE.tar $1 > /dev/null 2>>/backup/$1.bak.log/bin/gzip /backup/$1.$DATE.tarif [    $?  -eq  0      ]   then         echo "$1 $DATE backup suc

 用sed删除行首行尾的空格和Tab

摘要:sed 's/^[. ]\{1,\}//g' filesed 's/^ \+//' filesed "s/^ *//g" bbbbsed 's/^[ \t]*//'sed -r 's/^[[:blank:]]+//g'sed 's/^[[:blank:]]\+\(.*\)/\1/'用sed删除行首行尾的空格和Tab在UNIX上使用sed命令进行字符串处理中常常遇到的问题就是行首行尾的空格怎么删除。 下面介绍sed是怎样实现的,当然awk同样可以。  1:行首空格 sed 's/^[ \t]*//g'  说明:

 常用脚本命令集

摘要:如何用脚本实现分割文件 1.    #!/bin/bash2.    3.    if [ $# -ne 2 ]; then4.            echo 'Usage: split file size(in bytes)'5.            exit6.    fi7.    8.    file=$
分页:« 55 56 57 58 59 60 61 62 63 64 »
Powered by AKCMS