#关闭服务
#!/bin/bash
LANG=en

while :
do
    chkconfig --list |grep '3:on' |awk '{print $1}' > /tmp/on_sev.txt
    cat /tmp/on_sev.txt
    read -p "Please select a service from this list." s

    if ! grep -qw "$s" /tmp/on_sev.txt
    then
        echo "The service is not in the service list."
        continue
    fi
    chkconfig $s off
    break
done

#彻底杀死tomcat进程
#!/bin/bash
dir=/usr/local/tomcat/bin/bash

java_pc()
{
    pgrep java|wc -l
}

cd $dir
./shutdown.sh

count=0
while [ $count -lt 5 ]
do
    n=`java_pc`
    if [ $n -gt 0 ]
    then
        killall java
        count=$[$count+1]
        sleep 1
    else
        break
    fi
done

n=`java_pc`
if [ $n -gt 0 ]
then
    killall -9 java
fi

n=`java_pc`
if [ $n -gt 0 ]
then
    echo "tomcat 无法强制结束。"
    exit
fi

cd $dir
./startup.sh

#去掉文件后缀名
#!/bin/bash
for f in `ls -d ./*.bak`
do
    #mv $f `echo $f|sed 's/.bak$//'`
    f1=`echo $f|awk -F '.bak$' '{print $1}'`
    mv $f $f1
done

#检查域名是否过期
#!/bin/bash
[email protected]
t1=`date +%s`

is_install_whois()
{
    which whois &>/dev/null 
    if [ $? -ne 0 ]
    then
        yum install -y jwhois
    fi
}

notify()
{
    #e_d=`whois $1|grep 'Expiry Date' |awk '{print $4}' |cut -d 't' -f 1`
    e_d=`whois $1|grep 'Expiration'|tail -1 |awk '{print $5}' |awk -F 'T' '{print $1}'`
    if [ -z "$e_d" ]
    then
        e_d=`whois $1|grep 'Expiry Time' |awk '{print $3}'`
    fi
    e_t=`date -d "$e_d" +%s`
    n=`echo "86400*7"|bc`
    e_t1=$[$e_t-$n]
    e_t2=$[$e_t+$n]
    if [ $t1 -ge $e_t1 ] && [ $t1 -lt $e_t ]
    then
        python mail.py $mail_u "Domain $1 will to be expired." "Domain $1 expire date is $e_d."
    fi
    if [ $t1 -ge $e_t ] && [ $t1 -lt $e_t2 ]
    then
        python mail.py $mail_u "Domain $1 has bee expired." "Domain $1 expire date is $e_d."
    fi
}

if pgrep whois &>/dev/null
then
    killall -9 whois
fi

is_install_whois

notify aa.com &

#自动配置密钥认证
#!/bin/bash
read  -p "输入IP地址:" ip
read  -p "输入root密码:" pasd
is_install()
{
    if ! rpm -q $1 &>/dev/null
    then
        yum install -y $1
    fi
}

is_install openssh-cliens
is_install expect

if [ ! -f ~/.ssh/id_rsa.pub ]
then
    echo -e "\n" |ssh-keygen -P ''
fi

cat > key.expect <