운영 스크립트

3786 단어
Nginx 로그 분리 및 압축
$ cat  /data/tools/ngx_acclog.sh
#!/bin/bash

# ------------------------------------------------------
# -  :                                    
# -      Nginx           
# -                 dengwei 2016-02-14 09:36:15
# ------------------------------------------------------

source /etc/profile
source /etc/bashrc

PROCESS=$(ps -ef |grep '[n]ginx: master' |awk '{print $2}')
#  '[n]ginx'   grep -v grep  
test -z "$PROCESS" && exit 1

ngx_acclog_bak()
{
    local process="$PROCESS"
    local prefix='/data/backup/logs/ngx_access'
    local date=$(date -d "yesterday" +"%Y%m%d")
    local year_month=$(date -d "yesterday" +"%Y/%m")
    local bakdir="$prefix/$year_month"
    local nginx_sbin=$(readlink /proc/$process/exe)
    local logfiles=$(find /proc/$process/fd -maxdepth 1 -type l |xargs -I {} readlink {} |grep 'access.*.log')
    # local maxsize=1000000 # 1M byte

    test ! -d $bakdir && mkdir -p $bakdir

    for log in $logfiles; do
        #size=$(stat --printf="%s" log)
        #(( $size < $maxsize )) && continue
        local file=$(basename $log |sed 's!\.log$!!')
        mv $log ${bakdir}/${file}-${date}.log
    done

    /etc/init.d/nginx reload

    cd $bakdir && find ./ -name "access[-_]*\.log" -type f -print0 | ionice -c 3 nice -n 19 xargs -0 -I {} xz {}
}

ngx_acclog_bak

키 사용자 로그인 만들기
$ cat useradd-dba.sh 
#!/bin/bash

# tee /etc/sudoers.d/custom < /dev/null || useradd -g $group -G wheel $user
mkdir  -p /home/$user/.ssh
chmod 700 /home/$user/.ssh
tee -a /home/$user/.ssh/authorized_keys < /dev/null || useradd -g $group -G wheel $user
mkdir  -p /home/$user/.ssh
chmod 700 /home/$user/.ssh
tee -a /home/$user/.ssh/authorized_keys <

사용자 이름과 비밀번호가 일치합니다. 첫 번째 로그인은 비밀번호를 강제로 바꿉니다(현재 비밀번호를 입력한 다음에 새 비밀번호를 입력합니다).
#!/bin/bash

users=(chenbin chenjun dongji huyahui lilianghui)
group=develop

egrep opffs /etc/group >& /dev/null
if [ $? -ne 0 ]
then
    groupadd $group
fi

for user in  ${users[@]}
do
    id $user >& /dev/null
    if [ $? -ne 0 ]
    then
        useradd -g $group -G wheel  $user
        echo $user | passwd --stdin $user
        chage -d 0 $user
    fi
done

하드 드라이브 로그 수집:
#!/bin/bash
omsa_ttyperc_log()
{
    err_log="/tmp/omsa_err_log"
    file_time=$(date +%m%d)
    dir_name="/var/log"
    file_name="lsi_${file_time}.log"
    host_name=$(hostname)
    SN_numb=$(dmidecode -s system-serial-number)
    DCP_ip="10.40.6.64"
    DCP_dir="/var/log/TTY_log"
    comms=(omreport omconfig)

    for comm in ${comms[@]}
    do
        if ! which $comm >/dev/null 2>@1; then
            echo "$comm command not found"
            echo "no $comm installed!" > $err_log
            exit 1
        fi
    done

    perc_id=$(omreport storage controller |awk '$1 ~/^ID/ {print $3}')

    if [ -f ${dir_name}/${file_name} ];then
        echo "" > ${dir_name}/${file_name}
    fi
    
    omconfig storage controller action=exportlog controller=${perc_id} >/dev/null 2>$err_log 

    if [ $? -eq 0 ];then
        echo "tty perc log  !"
        if ! which expect  >/dev/null 2>@1; then
                yum -y install expect
        fi

        expect -c "
        spawn rsync ${dir_name}/${file_name} ${DCP_ip}:${DCP_dir}/${SN_numb}_${host_name}.log
        expect \"password:\"
        send \" 
\" expect off " else echo "tty perc log !" fi } #main omsa_ttyperc_log

좋은 웹페이지 즐겨찾기