加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

SHELL训练营--day29_shell练习86-90

发布时间:2020-12-15 23:01:37 所属栏目:安全 来源:网络整理
导读:#关闭服务 #!/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
#关闭服务 #!/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 <<EOF #!/usr/bin/expect set host [lindex $argv 0] set passwd [lindex $argv 1] spawn ssh-copy-id [email?protected]$host expect { "yes/no" { send "yesr"; exp_continue } "password:" {send "$passwdr" } } expect eof EOF chmod a+x key.expect ./key.expect $ip $pasd

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读