摘要:生产环境中安装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
2016年11月16日
对线上服务进行监控,如果死掉,就立即重启,以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
分类:Shell
2016年11月16日
检测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
2016年11月16日
系统初始化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
2016年11月16日
用SHELL脚本来防SSH和vsftpd暴力破解(第②版)
摘要:新近刚上的FTP备份服务器,例行检查/var/log/secure日志时,发现不少sshd和vsftpd失败认证信息,很明显有人想用暴力破解工具窃取密码,所以需要编写一个安全脚本防止。脚本需求如下:此SHELL脚本放在crontab计划任务里,每隔6小时(此时间根据实际情况来定义)就去读取/var/log/secure脚本,取出里面恶意猜测IP,如果单位时间内(一星期)的连接数是高于一个阀值,例如100(此阀
分类:Shell
2016年11月16日
用SHELL脚本自动化安装Nagios服务器端和客户端的
摘要:公司的一个项目网站,上线几天就因为磁盘暴满而出了问题,由于其服务器都集中在某一IDC机房内,所以考虑部署套Nagios监控报警系统,考虑到其它项目网站可能有类似需求,所以将其安装过程整理成脚本,方便以后的工作。Nagios服务器自动安装脚本,如下所示(此脚本在Centos5.5|5.6|5.8 x86_64下通过):12345678910111213141516171819202122232425262728293031323334353637383940
分类:Shell
2016年11月16日
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
2016年11月16日
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
2016年11月16日
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
分类:Shell
2016年11月16日
tar命令批量解压方法总结

分类:Shell
2016年11月16日
批量删除用户
摘要:#!/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
分类:Shell
2016年11月16日
批量添加用户
摘要:#!/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
分类:Shell
2016年11月16日
删除指定的登陆用户
摘要:#!/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
分类:Shell
2016年11月16日
测试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
分类:Shell
2016年11月16日
自动备份命令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
分类:Shell
2016年11月16日
用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' 说明:
分类:Shell
2016年11月16日
常用脚本命令集
摘要:如何用脚本实现分割文件 1. #!/bin/bash2. 3. if [ $# -ne 2 ]; then4. echo 'Usage: split file size(in bytes)'5. exit6. fi7. 8. file=$
分类:Shell
2016年11月16日
用tar编写脚本进行差量备份
摘要:#!/bin/shdate=`date +%m%d`sourcedir=/usr/aaatargetdir=/home/bbbcase $1 in 'f')#Full Backup outlogname=$targetdir/FO$date.log inlogname=$targetdir/FI$date.log echo Performing full bac
分类:Shell
2016年11月16日
Linux 查看网络流量具体实现
摘要:Linux 查看网络流量具体实现2010-06-13 15:08 佚名 csdn 我要评论(0) 字号:T | T数值有所变化,两者的差值就是过去一段时间的流量。可是,这也太不人性化了……正所谓自己动手,丰衣足食,我们自己来写一个Linux 查看网络流量脚本,实时显示并刷新!在GUI下面,有一大把的工具可以显示网络流量,那么,命令行下面怎么办?显然办法是有的,比如,ifconfig,Linux 查看网络流量会