mysql binlog -> sql 로 변환하기 스크립트

Posted by 주원이^^
2017.03.24 10:40 리눅스/스크립트

Mysql 복구 방법 중 binlog 파일을 이용한 복구 방법이 있다.

하지만 bin 파일이 작게는 수십개 많게는 몇백개 일 경우 

일일이 하나하나 복구하기에는 시간이 너무 소요 된다.


아래 스크립트는 find 명령어로 "*bin.000*" 파일을 긁어 온 다음에 while 문으로 기억 후

bin.0001 파일이 똑같이 순차적으로 0001.sql 로 변환 되는 스크립트. 

#/bin/sh

sql=.sql

find /usr/local/mysql/data/ -name "*bin.000*" |while read fa ; do


asd=`echo $fa|awk -F "." '{print $2}'`


/usr/local/mysql/bin/mysqlbinlog $fa > /usr/local/src/$asd.sql


done


#cd /usr/local/src 경로에 순차적으로 *.sql 파일이 생성 되어있다.

-rw-r--r--   1 root root    37914 2016-09-09 11:50 000001.sql
-rw-r--r--   1 root root  1526478 2016-09-09 11:49 000002.sql
-rw-r--r--   1 root root     1331 2016-09-09 11:49 000003.sql
-rw-r--r--   1 root root      635 2016-09-09 11:49 000004.sql


그럼 이제 

#cat *.sql > test2.sql 

명령어를 통해서 하나의 sql 파일로 만들어 주면 한번에 복구를 해버리면 된다.


그런데 사실 더 어이 없는건 위에 스크립트 상관없이 명령어 1줄로 bin파일을 하나의 sql파일 안에다가 순차적으로 담아낼 수 있으니


/usr/local/mysql/bin/mysqlbinlog mysql-bin.0* > /usr/local/src/test/test.sql


이 명령어 한번이면 끝난다. 그럼 1번부터 마지막 순번까지 순차적으로 내용이 들어가 있을 것이다.

그럼 그대로 복구 명령어 1줄

이렇게 2줄이면 끝난다. 

세상은 넓고 삽질은 끝도 없고 천재는 많으며 나는 오늘도 병신이였다.



출처: http://heartbleed.tistory.com/entry/MySql-binlog-파일-sql-파일로-변환-쉘스크립트 [HeartBleed]

'리눅스 > 스크립트' 카테고리의 다른 글

mysql binlog -> sql 로 변환하기 스크립트  (0) 2017.03.24
실시간 트래픽 체크  (0) 2017.02.02
system 정보보기 스크립트  (0) 2017.01.31
ssh_bruteforce 자동차단  (0) 2016.11.04
웹 트래픽 로그 순위 추출  (0) 2016.11.03
apache 자동다운받기  (0) 2016.03.04
이 댓글을 비밀 댓글로

실시간 트래픽 체크

Posted by 주원이^^
2017.02.02 13:01 리눅스/스크립트
#!/bin/bash 

echo "Time : receive (Kbit/Sec) / transmit (Kbit/Sec)"
while ( true ) ;
do
rx1=`grep eth0 /proc/net/dev | awk '{print $1}' | sed 's/.*://'`
tx1=`grep eth0 /proc/net/dev | awk '{print $9}'`

sleep 3

rx2=`grep eth0 /proc/net/dev | awk '{print $1}' | sed 's/.*://'`
tx2=`grep eth0 /proc/net/dev | awk '{print $9}'`
rx3=$(((rx2-rx1)/128/3))
tx3=$(((tx2-tx1)/128/3))

echo "`date '+%k:%M:%S'` : $rx3 / $tx3"
done


'리눅스 > 스크립트' 카테고리의 다른 글

mysql binlog -> sql 로 변환하기 스크립트  (0) 2017.03.24
실시간 트래픽 체크  (0) 2017.02.02
system 정보보기 스크립트  (0) 2017.01.31
ssh_bruteforce 자동차단  (0) 2016.11.04
웹 트래픽 로그 순위 추출  (0) 2016.11.03
apache 자동다운받기  (0) 2016.03.04
이 댓글을 비밀 댓글로

system 정보보기 스크립트

Posted by 주원이^^
2017.01.31 16:21 리눅스/스크립트

###########################################################

# Name of the script : syscheck-v1.2.sh

# Date              : 07/26/98

# Modified        : 11/15/04       By Jae. Hwa, Kim

# Version : 1.2

# This script collects System Configuration information.

# tar : sysinfo, error log , hacmp snap, x25backup, sna

###########################################################

DATE=`date +%m%d%y`

SRV=`uname -n`

RPT=./sys.$SRV.$DATE.txt

X25BACK=./x25.$SRV.$DATE.txt

HASNAP=/usr/es/sbin/cluster/snapshots/snap.$SRV.$DATE.*

ERRLOG=./err.$SRV.$DATE.txt

SYSTAR=./`uname -n`.`date +%m%d%y`.check.tar

mkdir ./x25backup

echo "System information will be saved on $RPT"

#TMP="/tmp"

#> ${PRT}

exec >> ${RPT} 2>&1

# Put the server and the date in the report

banner `uname -n`

echo " "

echo "                     %%%%%%%%%%%%%%%%%%%%%%%%%%%"

echo "                     System Configuration Report"

echo "                     %%%%%%%%%%%%%%%%%%%%%%%%%%%"

echo " "

echo `date `

echo " "

# General Information.

echo "######################"

echo "General Information"

echo "######################"

echo " "

prtconf

echo " "

echo " "

echo " "

# CPU_CLOCK.

echo "######################"

echo "CPU_CLOCK"

echo "######################"

echo " "

CPU_CLOCK.exe

echo " "

echo " "

echo " "

# General OS Information.

echo "######################"

echo "General OS Information"

echo "######################"

echo " "

# Check the Operating System Level in the report

echo "=============================================="

echo "<< `uname -n` -- AIX Operating System Level >>"

echo "=============================================="

echo " "

echo "---------------------------------------"

echo "Lists names of known maintenance levels"

echo "---------------------------------------"

echo " "

/usr/bin/oslevel -q

echo " "

echo "-----------------------------------------------------------------"

echo "Lists fileset at levels later than the current maintenance levels"

echo "-----------------------------------------------------------------"

echo " "

/usr/bin/oslevel -r

echo " "

echo " "

echo "===================================="

echo "<< `uname -n` -- Boot Information >>"

echo "===================================="

echo " "

echo "--------------------"

echo "The last boot Device"

echo "--------------------"

echo " "

/usr/sbin/bootinfo -b

echo " "

echo "------------------------------------"

echo "The Booting Kernel Mode(32bit/64bit)"

echo "------------------------------------"

echo "H/W    Mode : "`/usr/sbin/bootinfo -y`" bit"

echo "Kernel Mode : "`/usr/sbin/bootinfo -K`" bit"

echo " "

echo "-----------------"

echo "The System uptime"

echo "-----------------"

uptime

echo " "

echo " "


# Put the system attributes in the report

echo "======================================================================="

echo "<< `uname -n` -- System Attribute information (lsattr -E -H -l sys0) >>"

echo "======================================================================="

echo " "

lsattr -E -H -l sys0

echo " "

# Put the machinetype info in the report

echo "=============================================="

echo "<< `uname -n` -- System Information (lscfg) >>"

echo "=============================================="

echo " "

lscfg -vp

echo " "

# Print the Processor on this server

echo "========================================="

echo "<< `uname -n` -- Processor information >>"

echo "========================================="

echo " "

/usr/sbin/bindprocessor -q

echo " "

# Print the amount of memory on this server

echo "======================================"

echo "<< `uname -n` -- Memory information >>"

echo "======================================"

echo " "

echo "-----------------------"

echo "The Size of real memory"

echo "-----------------------"

echo " "

/usr/sbin/bootinfo -r

echo " "

# Put the OS-dump info in the report

echo "===================================="

echo "<< `uname -n` -- DUMP information >>"

echo "===================================="

echo " "

echo "-------------------"

echo "Current Dump Device"

echo "-------------------"

echo " "

sysdumpdev -l

echo " "

echo "--------------------"

echo " Estimated Dump Size"

echo "--------------------"

echo " "

sysdumpdev -e

echo " "

# Put the OS-page space info in the report

echo "========================================="

echo "<< `uname -n` -- Paging space information"

echo "========================================="

echo " "

lsps -a

echo " "

echo "======================================="

echo "<< `uname -n` -- Disk Usage Information"

echo "======================================="

echo " "

df -tk

echo " "

echo "======================================="

echo "<< `uname -n` -- Slot Information"

echo "======================================="

echo " "

lsslot -c pci

echo " "

# Print physical scsi adapter and disk info

echo "======================================================="

echo "<< `uname -n` -- SCSI adapter and physical disk info >>"

echo "======================================================="

echo " "

lscfg | grep -i scsi | grep -i -E "adapter|controller"

echo " "

lsdev -Cc disk

echo " "

echo "======================================="

echo "<< `uname -n` -- Crontab Information >>"

echo "======================================="

echo " "

crontab -l

echo " "

echo "==============================================="

echo "<< `uname -n` -- File System export Information"

echo "==============================================="

echo " "

exportfs

echo " "

echo "========================================="

echo "<< `uname -n` -- Alog Boot Information >>"

echo "========================================="

echo " "

echo " "

alog -o -f /var/adm/ras/bootlog

echo " "

echo " "

echo " "

echo " "

echo "========================================="

echo "<< `uname -n` -- User License Information"

echo "========================================="

echo " "

echo " "

lslicense

echo " "

echo " "

echo " "

echo " "

# LVM Information

echo "#################"

echo " LVM Information "

echo "#################"

echo " "

echo " "

echo " "

# List all VG

# Find all the disks in the machine then print info

echo "======================================"

echo "<< `uname -n` -- List all volume group"

echo "======================================"

echo " "

echo "-------------"

echo "Volume Groups"

echo "-------------"

echo " "

echo "List Volume Group"

lsvg

echo " "

echo "List On-line Volume Group"

echo " "

lsvg -o

echo " "

echo "----------------"

echo "Physical Volumes"

echo "----------------"

lspv

echo " "

echo " "

echo " "

lsvg | while read VG

do

 echo " "

 echo "The following physical volumes are in Volume Group -- $VG --"

 lsvg -p $VG

 echo " "

 echo "<< Volume group info for $VG"

 lsvg $VG

 echo " "

 echo " "

 echo " "

done

echo " "

# List physical disk info

echo "=========================================================="

echo "<< `uname -n` -- List all physical volumes by volume group"

echo "=========================================================="

echo " "

getlvodm -C | while read VOL

do

 echo " "

 echo "<< Physical volume info for $VOL by PVID >>"

 lspv $VOL

 echo " "

 echo "<< Physical volume info for $VOL by logical volume >>"

 lspv -l $VOL

 echo " "

 echo "<< Physical volume info for $VOL by PP Range >>"

 lspv -p $VOL

 echo " "

 echo " "

 echo " "

done

echo " "

# List all logical volumes by volume group

echo "========================================================="

echo "<< `uname -n` -- List all logical volumes by volume group"

echo "========================================================="

echo " "

lsvg -o | while read VG

do

 echo "<< List of logical volumes defined in volume group $VG >>"

 lsvg -l $VG

 echo " "

 echo "<< List of physical volumes defined in volume group $VG >>"

 lsvg -p $VG

 echo " "

 echo " "

 echo " "

done

echo " "

# Save the mount information in the report

echo "====================================="

echo "<< `uname -n` -- Mount information >>"

echo "====================================="

echo " "

mount

echo " "

# Print the file system information

echo "========================================="

echo "<< `uname -n` -- List all file systems >>"

echo "========================================="

echo " "

lsfs -l

echo " "

# Network Information

echo "###################"

echo "Network Information"

echo "###################"

echo " "

echo " "

# Check Network Option

echo "================================================="

echo "<< `uname -n` -- Network Option Tunable Values >>"

echo "================================================="

echo " "

echo "-------------------------------"

echo "Important Network Option Values"

echo "-------------------------------"

echo " "

no -a | grep thewall

no -a | grep sb_max

no -a | grep tcp_sendspace

no -a | grep tcp_recvspace

no -a | grep udp_sendspace

no -a | grep udp_recvspace

no -a | grep rfc1323

no -a | grep tcp_mssdflt

no -a | grep ipforwarding

no -a | grep tcp_pmtu_discover

no -a | grep udp_pmtu_discover

echo " "

echo " "

# Put the network information in the report

echo "================================================="

echo "<< `uname -n` -- Network information (netstat) >>"

echo "================================================="

echo " "

echo "-----------"

echo "netstat -nr"

echo "-----------"

netstat -nr

echo " "

echo "----------"

echo "netstat -i"

echo "----------"

netstat -i

echo " "

echo "----------"

echo "netstat -m"

echo "----------"

netstat -m

echo " "

echo "----------"

echo "netstat -v"

echo "----------"

netstat -v

echo " "


# Improtant Files

echo "###########################"

echo "Important Files Information"

echo "###########################"

echo " "

echo " "

echo " "

echo "========================================"

echo "<< `uname -n` -- some Important files >>"

echo "========================================"

echo " "

echo "------------"

echo "/etc/inittab"

echo "------------"

cat /etc/inittab

echo " "

#echo " "

echo "----------"

echo "/etc/hosts"

echo "----------"

cat /etc/hosts

echo " "

#echo " "

echo "----------------"

echo "/etc/resolv.conf"

echo "----------------"

cat /etc/resolv.conf

echo " "

#echo " "

echo "---------"

echo "/etc/motd"

echo "---------"

cat /etc/motd

echo " "

#echo " "

echo "-----------"

echo "/etc/passwd"

echo "-----------"

cat /etc/passwd

echo " "

#echo " "

echo "----------"

echo "/etc/group"

echo "----------"

cat /etc/group

echo " "

3echo " "

echo "------------"

echo "/etc/profile"

echo "------------"

cat /etc/profile

echo " "

#echo " "

echo "------------------"

echo "/etc/security/user"

echo "------------------"

cat /etc/security/user

echo " "

#echo " "

echo "--------------------"

echo "/etc/security/limits"

echo "--------------------"

cat /etc/security/limits

echo " "

#echo " "

echo "-----------------------"

echo "/etc/security/login.cfg"

echo "-----------------------"

cat /etc/security/login.cfg

echo " "

#echo " "

echo "---------------------"

echo "/etc/security/environ"

echo "---------------------"

cat /etc/security/environ

echo " "

#echo " "

echo "-------------"

echo "/etc/services"

echo "-------------"

cat /etc/services

echo " "

#echo " "

echo "----------------"

echo "/etc/filesystems"

echo "----------------"

cat /etc/filesystems

echo " "

#echo " "

echo "-----------"

echo "/etc/rc.net"

echo "-----------"

cat /etc/rc.net

echo " "

echo " "

echo " "

echo " "

echo "-----------"

echo "    aio    "

echo "-----------"

lsattr -El aio0

echo " "

echo " "

echo " "

echo " "

# List Software Installed.

echo "####################"

echo "Software Information"

echo "####################"

echo " "

# Get the LPP information

echo "==========================================================="

echo "<< `uname -n` -- List all LPPs installed on this machine >>"

echo "==========================================================="

echo " "

lslpp -L all

echo " "

echo " "

echo " "

echo " "

# SNA config & status & backup

echo "####################"

echo "SNA config & status"

echo "####################"

echo " "

echo "========================="

echo "<< `uname -n` -- SNA >>"

echo "========================="

echo "-----------------------------"

echo "<< `uname -n` -- SNA status >>"

echo "-----------------------------"

mpcinfo

echo " "

ListRAS

echo " "

sna -d l

echo " "

sna -d s

echo " "

echo "==================="

echo "SNA config Backup "

echo "==================="

cat /etc/sna/sna_node.cfg

echo " "

echo " "

# X.25 config & status & backup

echo "####################"

echo "X.25 config & status"

echo "####################"

echo " "

echo "========================="

echo "<< `uname -n` -- x.25  >>"

echo "========================="

echo "-----------------------------"

echo "<< `uname -n` -- x25status >>"

echo "-----------------------------"

x25status

echo " "

echo "-------------------------"

echo "<< `uname -n` -- lsx25 >>"

echo "-------------------------"

lsx25

echo " "

echo "==================="

echo "X.25 config Backup "

echo "==================="

backupx25 -d /x25backup -v

echo " "

echo " "

echo " "

# HACMP config & status & backup

echo "#####################"

echo "HACMP Config & status"

echo "#####################"

echo " "

echo "-----------------------------------"

echo "<< `uname -n` HACMP Daemon status >>"

echo "-----------------------------------"

echo "Cluster status"

lssrc -a |egrep 'svc|ES'

lssrc -ls snmpd

lssrc -ls topsvcs 

lssrc -ls emsvcs 

lssrc -ls emaixos

lssrc -ls grpsvcs

echo " "

echo " "

echo " "

echo "======================================"

echo "<< `uname -n` -- HACMP Information  >>"

echo "======================================"

echo "-------------------------------------"

echo "<< `uname -n` HACMP Cluster config >>"

echo "-------------------------------------"

echo "<< Cluster info >>"

/usr/es/sbin/cluster/utilities/cllsclstr

echo " "

echo "<< Cluster Node info >>"

/usr/es/sbin/cluster/utilities/cllsnode

echo " "

echo "<< Cluster Node interface info >>"

/usr/es/sbin/cluster/utilities/cllsif

echo " "

echo "<< Cluster resources group >>"

/usr/es/sbin/cluster/utilities/cllsgrp

echo " "

echo "<< Cluster resource group information >>"

/usr/es/sbin/cluster/utilities/cllsgrp  | while read REG

do

   echo "-----------------------"$REG" information-----------------------------"

   /usr/es/sbin/cluster/utilities/clshowres -g $REG

   echo " "

done

echo "------------------------------"

echo "<< `uname -n` -- HACMP SNAP >>"

echo "------------------------------"

/usr/es/sbin/cluster/utilities/clsnapshot -c -i -n snap.$SRV.$DATE  -d  'ha snap'

echo "###########################"

echo "`uname -n` system error log"

echo "###########################"

echo "--------------------------------------"

echo "<< `uname -n` -- errpt > $ERRLOG >>"

echo "--------------------------------------"

errpt >> $ERRLOG

echo "--------------------------------------"

echo "<< `uname -n` -- errpt -a >> $ERRLOG >>"

echo "--------------------------------------"

errpt -a >> $ERRLOG

echo " "

echo "==== tar compress ===="

tar cvf $SYSTAR $RPT $HASNAP ./x25backup $ERRLOG

echo "<< End of the Document for `uname -n` >>"

# End of the Script

# remove status file

rm $RPT $HASNAP $X25BACK $ERRLOG

rmdir x25backup

'리눅스 > 스크립트' 카테고리의 다른 글

mysql binlog -> sql 로 변환하기 스크립트  (0) 2017.03.24
실시간 트래픽 체크  (0) 2017.02.02
system 정보보기 스크립트  (0) 2017.01.31
ssh_bruteforce 자동차단  (0) 2016.11.04
웹 트래픽 로그 순위 추출  (0) 2016.11.03
apache 자동다운받기  (0) 2016.03.04
이 댓글을 비밀 댓글로

ssh_bruteforce 자동차단

Posted by 주원이^^
2016.11.04 17:20 리눅스/스크립트

#!/bin/bash

#횟수설정

sshban="15"

##################################

declare -a ssh_deny_ip_array

search_today=`date +'%b %e'`

today=`date +%Y%m`

time=`date +'%Y:%m:%d %H:%M:%S'`

log="/usr/local/logs/ssh_ban_$today"


_check() {

if [ ! -d /usr/local/logs ]; then

mkdir -p /usr/local/logs

fi


if [ ! -f /etc/hosts.deny  ]; then

touch /etc/hosts.deny

fi


if [ ! -f $log ]; then

touch $log

fi

}


_log() {

log_ip_cnt=${#ssh_deny_ip_array[@]}

echo "[ ${time} ]" >> $log

echo "" >> $log


for ((i=0;i<=$log_ip_cnt;i++)); do

echo ${ssh_deny_ip_array[$i]} >> $log

done

echo "" >> $log


}



_common() {

declare -a ssh_ip_ban_list_array

#오늘날짜 검색이후 IP추출 및 비교후 데이터저장

IFS=$'\n' ssh_ip_count_list=(`cat /var/log/secure | grep 'Failed password for' | egrep -v 'invalid user' | grep ${search_today} |  awk '{print $11}' |  sort -rn -k 11 | uniq -c | awk '{print $1}'`)


k="0"

j="1"

for value in "${ssh_ip_count_list[@]}"; do

if [ $value -ge $sshban ]; then

ssh_ip_list=`cat /var/log/secure | grep 'Failed password for' | egrep -v 'invalid user' | grep ${search_today} |  awk '{print $11}' |  sort -rn -k 11 | uniq -c | awk '{print $2}' | sed -n "${j},${j}p"`

ssh_ip_ban_list_array[$k]=`echo $ssh_ip_list`

k=`expr $k + 1`

fi

j=`expr $j + 1`

done



#기존 리스트 비교 후 삽입

declare -a ssh_deny_ip

u=0;

ssh_ip_ban_cnt=${#ssh_ip_ban_list_array[@]}

for ((i=0;i<$ssh_ip_ban_cnt;i++)); do

ssh_deny_ip_switch="n"

while read line; do

if [[ `echo $line | grep ^S` ]] || [[ `echo $line | grep ^s` ]]; then

ssh_deny_ip=`echo $line | awk '{print $3}'`

if [[ "${ssh_ip_ban_list_array[$i]}"  == "$ssh_deny_ip" ]]; then

ssh_deny_ip_switch="y"

break

fi


fi

done < /etc/hosts.deny

if [[ $ssh_deny_ip_switch == "n" ]]; then

echo "sshd : ${ssh_ip_ban_list_array[$i]}" >> /etc/hosts.deny

ssh_deny_ip_array[$u]=${ssh_ip_ban_list_array[$i]}

u=`expr $u + 1`

fi


done


if [ ! -z `echo ${ssh_deny_ip_array[@]}` ]; then

_log

fi

}






_check

_common

'리눅스 > 스크립트' 카테고리의 다른 글

실시간 트래픽 체크  (0) 2017.02.02
system 정보보기 스크립트  (0) 2017.01.31
ssh_bruteforce 자동차단  (0) 2016.11.04
웹 트래픽 로그 순위 추출  (0) 2016.11.03
apache 자동다운받기  (0) 2016.03.04
mysql replication 상태체크  (0) 2016.01.13
이 댓글을 비밀 댓글로

웹 트래픽 로그 순위 추출

Posted by 주원이^^
2016.11.03 11:43 리눅스/스크립트

#!/bin/bash
stty erase ^H
check="no"
#출력 기본값
view_number="20"

declare -a http_log_size_array
declare -a http_log_ip_array
declare -a http_log_filename_array

_comm() {
apache_log_file=""

#같은파일 중복제거 , 카운트
http_log_cnt="`cat $2 | awk '!x[$7]++' | sort -rn -k 10 | wc -l`"

#같은파일 중복제거, 문자열 내용 변수저장
IFS=$'\n' http_log_text=(`cat $2 | awk '!x[$7]++' | sort -rn -k 10`)

view_number=$1

#트래픽합산결과
total_sum=`cat $2 | awk '{sum += $10} END {print sum/1024000,"MByte"}'`

#리스트 배열에 담기 ip,filename,size 3개
#line 한줄출력
k="0"
http_log_number="0"

for value in "${http_log_text[@]}"; do
 if [[ $k -ge $view_number ]]; then
  break;
 fi

 echo "number : $k        total_number : $view_number "
 http_log_filename=`echo $value | awk '{print $7}'`
 http_log_ip=`echo $value | awk '{print $1}'`
 http_log_size=`echo $value | awk '{print $10}'`

 http_log_filename_array[$http_log_number]=${http_log_filename}
 http_log_ip_array[$http_log_number]=${http_log_ip}
 http_log_size_array[$http_log_number]=`echo ${http_log_size} | awk '{sum += $1} END {print sum/1024000,"MByte"}'`

 k=`expr $k + 1`
 http_log_number=`expr $http_log_number + 1`
 clear
done

#트래픽 용량 출력
echo -ne "Total Traffic $1 List
"
m=0

#트래픽 출력

for ((j=1;j<=$view_number;j++)); do
  echo  "${j}) ${http_log_filename_array[$m]} ${http_log_ip_array[$m]} ${http_log_size_array[$m]}"

  m=`expr $m + 1`
done

echo -ne "
1) Menu  2) Log File modify 3) View number modify x) exit
select number "

read select_comm
 case $select_comm in
  1)
   clear
   _default_select
   ;;
  2)
   if [[ ! -z $http_log_file_menu ]]; then
    http_log_dir="${http_log_file_menu}"
    http_log_dir_list="`ls $http_log_dir | grep log$`"
    http_log_dir_cnt=`ls $http_log_dir | grep log$ | wc -l`
    for ((i=1;i<=$http_log_dir_cnt;i++)); do
     http_log_dir_list=`ls $http_log_dir | grep log$ | sed -n "${i},${i}p"`
     http_log_dir_array[$i]=$http_log_dir_list
     echo "${i}) $http_log_dir_list"
    done
    echo "select log file number?"
    read http_log_file_number
    http_log_file="${http_log_dir}/${http_log_dir_array[$http_log_file_number]}"
   fi
   _comm "$view_number" "$http_log_file"
   ;;
  3)
   echo -ne " before : $view_number
modify number?"
                        read modify_view_number
                        view_number=`echo $modify_view_number | sed 's/[^0-9]//g'`
    
   clear
   _comm "$view_number" "$http_log_file"

   ;;
  x)
   exit
   ;;
 esac
}

_default_select() {
clear
while [ $check=no ]; do
echo -ne "
================ Default Information ================
1)Http Log File : $http_log_file

ex) /usr/local/apache/logs/transferlog

2)View number : $view_number

s) Start        x) Exit
======================================================
select number?"
read menu_select
        case $menu_select in
                1)
   echo -ne "
1)/usr/local/apache/logs/transferlog 2)input Dir
select number?"
#폴더 선택 및 파일 선택
   read http_log_file_menu
    case $http_log_file_menu in
     1)
      http_log_dir="/usr/local/apache/logs/transferlog"
      http_log_dir_list="`ls $http_log_dir | grep log$`"
      http_log_dir_cnt=`ls $http_log_dir | grep log$ | wc -l`
      for ((i=1;i<=$http_log_dir_cnt;i++)); do
       http_log_dir_list=`ls $http_log_dir | grep log$ | sed -n "${i},${i}p"`
       http_log_dir_array[$i]=$http_log_dir_list
       echo "${i}) $http_log_dir_list"
      done
      echo "select log file number?"
      read http_log_file_number
      http_log_file="${http_log_dir}/${http_log_dir_array[$http_log_file_number]}"
      _default_select
      ;;
     2) 
      echo "input your directory "
      read http_log_file_menu
      if [[ ! -z $http_log_file_menu ]]; then
       http_log_dir="${http_log_file_menu}"
       http_log_dir_list="`ls $http_log_dir | grep log$`"
       http_log_dir_cnt=`ls $http_log_dir | grep log$ | wc -l`
       for ((i=1;i<=$http_log_dir_cnt;i++)); do
        http_log_dir_list=`ls $http_log_dir | grep log$ | sed -n "${i},${i}p"`
        http_log_dir_array[$i]=$http_log_dir_list
        echo "${i}) $http_log_dir_list"
       done
       echo "select log file number?"
       read http_log_file_number
       http_log_file="${http_log_dir}/${http_log_dir_array[$http_log_file_number]}"
      fi
      _default_select
      ;;
    esac


   _default_select
   ;;
                2)
                        echo -ne "View number?"
                        read tmp_view_number
                        tmp2_view_number=`echo $tmp_view_number | sed 's/[^0-9]//g'`
                        if [[ ! -z "$tmp2_view_number" ]]; then
                                view_number=${tmp2_view_number}
                                _default_select
                        else
                                _default_select
   fi
                        ;;

  x)
   exit
   ;;
   
  *)
  clear
  if [[ ! -z $http_log_dir ]] && [[ ! -z $view_number ]]; then
   _comm "$view_number" "$http_log_file"
  fi
  _default_select
  ;;

        esac
clear
_default_select
done
}

_default_select

 

log.txt

 

'리눅스 > 스크립트' 카테고리의 다른 글

system 정보보기 스크립트  (0) 2017.01.31
ssh_bruteforce 자동차단  (0) 2016.11.04
웹 트래픽 로그 순위 추출  (0) 2016.11.03
apache 자동다운받기  (0) 2016.03.04
mysql replication 상태체크  (0) 2016.01.13
폴더내 파일 소문자로 일괄변경  (0) 2015.07.16
이 댓글을 비밀 댓글로

apache 자동다운받기

Posted by 주원이^^
2016.03.04 06:22 리눅스/스크립트

#!/bin/bash


folder="/httpd"
name="httpd"
start="1"
end="20"

ls -l /httpd | awk -F " " '{print $8}' > /httpd/httpd_list.txt

cd $folder
for ((i=$start;i<=$end;i++)); do
        start_cnt=`ls -l | grep ${name}-${i} | wc -l`
        if [[ $start_cnt != 0 ]]; then
                for ((j=$start;j<=$end;j++)); do
                        middle_cnt=`ls -l | grep ${name}-${i}.${j} | wc -l`
                        if [[ $middle_cnt != 0 ]]; then
                                if [[ `ls -l | grep ${name}-${i}.${j}.last | wc -l` != 0 ]]; then
                                        rm_name="`ls -v | grep ${name}-${i}.${j}.last`"
                                        rm -rf "$rm_name"
                                fi
                                        end_cnt=`ls -v | grep ${name}-${i}.${j} | wc -l`
                                        sed_name=`ls -v | grep ${name}-${i}.${j} | sed "/${name}-${i}.${j}.last/d" | sed -n "${end_cnt},${end_cnt}p"`
                                        ln -s ${sed_name} ${name}-${i}.${j}.last.tar.gz
                        fi
                        continue
                done
        fi

done

curl http://archive.apache.org/dist/httpd/ | grep httpd-2 | grep tar.gz | awk -F "href=\"" '{print $2}' | awk -F " " '{print $1}' | awk -F "\"" '{print $1}' | grep tar.gz$ | grep -v alpha | grep -v deps | grep -v beta > /httpd/httpd_list
_http_list

while read line; do
        while read line2; do
                if [[ $line == $line2 ]]; then
                        check=0
                        break;
                else
                        check=1
                fi
        done < /httpd/httpd_list
        if [ $check == 1 ]; then
                wget -O /httpd/$line http://archive.apache.org/dist/httpd/$line
        fi
done < /httpd/httpd_list.txt 
ls -l /httpd | awk -F " " '{print $8}' > /httpd/httpd_list.txt
rm -rf /httpd/httpd_list

'리눅스 > 스크립트' 카테고리의 다른 글

ssh_bruteforce 자동차단  (0) 2016.11.04
웹 트래픽 로그 순위 추출  (0) 2016.11.03
apache 자동다운받기  (0) 2016.03.04
mysql replication 상태체크  (0) 2016.01.13
폴더내 파일 소문자로 일괄변경  (0) 2015.07.16
7일뒤 로그 삭제  (0) 2015.07.14
이 댓글을 비밀 댓글로

mysql replication 상태체크

Posted by 주원이^^
2016.01.13 13:54 리눅스/스크립트

#!/bin/bash
#Server infomation
DB_ID="root"
DB_PW="12345"
S_ip=`ifconfig | grep "inet addr" | awk '{print $2}' | awk -F ":" '{print $2}' | head -n 1`
S_Hostname=`hostname`
Sql_ver=`/usr/local/mysql/bin/mysql -V | awk -F " " '{print $5}' | awk -F "," '{print $1}'`

#log check
Source="/usr/bin/"

##time setting
Log_DeleteDay="42"
Log_Time="*/1 * * * * root sh"

Time_Day="`/bin/date +%Y%m%d --date "$Day days ago"`"
Time_Second="`/bin/date +%H%M%S --date "$Day days ago"`"
#sendmail info
TITLE="[${S_ip}]Mysql Replication Error $S_Hostname"
To_mail="메일주소"


#SQL infomation
MASTER_HOST="`/usr/local/mysql/bin/mysql -u${DB_ID} -p${DB_PW} -e "show slave status \G" | grep Master_Host: | awk -F " " '{print $2}'`"
MASTER_POS="`/usr/local/mysql/bin/mysql -u${DB_ID} -p${DB_PW} -e "show slave status \G" | grep Read_Master_Log_Pos: | awk -F " " '{print $2}'`"
SLAVE_POS="`/usr/local/mysql/bin/mysql -u${DB_ID} -p${DB_PW} -e "show slave status \G" | grep Exec_Master_Log_Pos: | awk -F " " '{print $2}'`"
SLAVE_IO="`/usr/local/mysql/bin/mysql -u${DB_ID} -p${DB_PW} -e "show slave status \G" | grep Slave_IO_Running: | awk -F " " '{print $2}'`"
SLAVE_SQL="`/usr/local/mysql/bin/mysql -u${DB_ID} -p${DB_PW} -e "show slave status \G" | grep Slave_SQL_Running: | awk -F " " '{print $2}'`"

Log_check() {
if [ ! -d /usr/logs ]; then
        mkdir -p ${Source}logs
fi
if [ ! -f ${Source}logs/sql_replication_${Time_Day}.log ]; then
        touch ${Source}logs/sql_replication_${Time_Day}.log
fi
if [[ -z `grep "##Sql Replication Check" "/etc/crontab" | head -n 1` ]]; then
        echo -ne "##Sql Replication Check
${Log_Time} ${Source}Sql_replication.sh" >> /etc/crontab
/etc/init.d/crond restart
fi
}

Log_delete() {

`find ${Source}logs/sql_replication* -ctime +${Log_DeleteDay} -exec rm -rf {} \;`

}


Content() {
echo -ne "
Master Host : $MASTER_HOST
Master Pos : $MASTER_POS        Slave Pos : $SLAVE_POS
Slave IO : $SLAVE_IO            Slave SQL : $SLAVE_SQL
Mysql Version : $Sql_ver
"
}

Mail() {
        Content | /bin/mail -s "${TITLE}" ${To_mail}
}

Start() {
Log_check

echo -ne "  #####$Time_Second#####" >> ${Source}logs/sql_replication_${Time_Day}.log

Content >> ${Source}logs/sql_replication_${Time_Day}.log

if [[ $SLAVE_IO != Yes ]] && [[ $SLAVE_SQL != Yes ]]; then
        Mail
elif [[ $MASTER_POS != $SLAVE_POS ]]; then
        Mail
fi

Log_delete
}

Start

 

'리눅스 > 스크립트' 카테고리의 다른 글

웹 트래픽 로그 순위 추출  (0) 2016.11.03
apache 자동다운받기  (0) 2016.03.04
mysql replication 상태체크  (0) 2016.01.13
폴더내 파일 소문자로 일괄변경  (0) 2015.07.16
7일뒤 로그 삭제  (0) 2015.07.14
특정데몬 모니터링  (0) 2014.11.06
이 댓글을 비밀 댓글로

폴더내 파일 소문자로 일괄변경

Posted by 주원이^^
2015.07.16 17:28 리눅스/스크립트

 

#! /bin/bash

 for filename in *
do
   fname=`basename $filename`
   n=`echo $fname | tr A-Z a-z`
  if [ "$fname" != "$n" ]
   then
     mv $fname $n
   fi
done
exit 0

'리눅스 > 스크립트' 카테고리의 다른 글

apache 자동다운받기  (0) 2016.03.04
mysql replication 상태체크  (0) 2016.01.13
폴더내 파일 소문자로 일괄변경  (0) 2015.07.16
7일뒤 로그 삭제  (0) 2015.07.14
특정데몬 모니터링  (0) 2014.11.06
watch  (0) 2014.11.05
이 댓글을 비밀 댓글로

7일뒤 로그 삭제

Posted by 주원이^^
2015.07.14 09:54 리눅스/스크립트

httpd 로그 삭제.

 

/usr/bin/find "/var/log/httpd/" -mtime +7 -exec rm -rf {} \;

'리눅스 > 스크립트' 카테고리의 다른 글

mysql replication 상태체크  (0) 2016.01.13
폴더내 파일 소문자로 일괄변경  (0) 2015.07.16
7일뒤 로그 삭제  (0) 2015.07.14
특정데몬 모니터링  (0) 2014.11.06
watch  (0) 2014.11.05
부팅후 IP변경되면 메일로 알려주기  (0) 2014.08.04
이 댓글을 비밀 댓글로

특정데몬 모니터링

Posted by 주원이^^
2014.11.06 12:48 리눅스/스크립트

vi process_check.sh

----------------------------------------------

#!/bin/sh
check=`ps -ef | grep httpd | wc | awk '{print$1}'`

if [ $check -gt 2 ]
then
exit 0
else
/usr/local/apache/bin/apachectl start
fi

 

'리눅스 > 스크립트' 카테고리의 다른 글

폴더내 파일 소문자로 일괄변경  (0) 2015.07.16
7일뒤 로그 삭제  (0) 2015.07.14
특정데몬 모니터링  (0) 2014.11.06
watch  (0) 2014.11.05
부팅후 IP변경되면 메일로 알려주기  (0) 2014.08.04
clamav 리눅스용 바이러스 실행  (0) 2014.08.01
이 댓글을 비밀 댓글로