shell的常用脚本一

批量创建用户名脚本:

 1 #########################################################################
 2 #    File Name: create-user.sh
 3 #    Author: kingle
 4 #    Mail: kingle122@vip.qq.com 
 5 #    Created Time: Mon 06 Aug 2018 04:17:12 PM CST
 6 #########################################################################
 7 #!/bin/bash
 8 user="kingle"
 9 passfile="./passwd.txt"
10 for i in `seq -w 10`
11 do
12     useradd $user$i
13     "`echo "$RANDOM"|md5sum|cut -c5-15`" = pass
14     echo "$pass"|passwd --stdin $user$num
15     echo -e "user:$user$num\tpasswd:$pass" >>$passfile
16 done
17 echo --------------------------ok--------------------
18 cat $passfile

批量删除用户:

#########################################################################
#    File Name: deluser.sh
#    Author: kingle
#    Mail: kingle122@vip.qq.com 
#    Created Time: Mon 06 Aug 2018 04:17:12 PM CST
#########################################################################


#!/bin/sh
for user in kingle{01..10}
do
    userdel -r $user
    echo "delete $user is ok"
done

扫描内网存活主机

 1 #########################################################################
 2 #    File Name: scan_ip.sh
 3 #    Author: kingle
 4 #    Mail: kingle122@vip.qq.com 
 5 #    Created Time: Mon 06 Aug 2018 04:17:12 PM CST
 6 #########################################################################
 7 #!/bin/bash
 8 Ip_file=./scan_ip.txt
 9 >$Ip_file
10 for i in 10.0.0.{1..254}
11 do
12     ping -c 1 -W 1 $i &>/dev/null && \
13     if [ $? -eq 0 ];then
14     echo "chunzhu: $i" &>>$Ip_file
15         
16 fi    &
17 done 
18 echo "hahhahah:"
View Code

nmap扫描:

 1 #########################################################################
 2 #    File Name: namp.sh
 3 #    Author: kingle
 4 #    Mail: kingle122@vip.qq.com 
 5 #    Created Time: Mon 06 Aug 2018 04:17:12 PM CST
 6 #########################################################################
 7 #!/bin/bash
 8 CMD="nmap -sP"
 9 IP="10.0.0.0/24"
10 CMD2="nmap -sS"
11 $CMD $IP|awk '/Nmap scan report for/ {print $NF}'
View Code

测试网站通否:

 1 #########################################################################
 2 #    File Name: test——url.sh
 3 #    Author: kingle
 4 #    Mail: kingle122@vip.qq.com 
 5 #    Created Time: Mon 06 Aug 2018 04:17:12 PM CST
 6 #########################################################################
 7 #!/bin/bash
 8 . /etc/init.d/functions
 9 check_count=0
10 url_list=(
11 http://10.0.0.200
12 http://10.0.0.201
13 http://10.0.0.202
14 http://www.baidu.com
15 )
16 function wait(){
17     echo -n 'waitting 3 misth--------';
18     for ((i=0;i<3;i++))
19     do
20     echo -n ".";sleep 1
21     done
22     echo
23 }
24 function check_url(){
25     wait
26     for ((i=0; i<`echo ${#url_liset[*]}`; i++))
27     do
28         wget -o /dev/null -T 3 --tries=2 --spider ${url_list[$i]} >/dev/null
29     if [ $? -eq 0 ]
30     then
31     action "${url_list[$i]}" /bin/true
32     else
33     action "${url_list[$i]}" /bin/false
34     fi
35 done
36     ((check_count++))
37 
38 }
39 main(){
40     while true
41     do
42         check_url
43         echo "-------check count:${check_count}"
44         sleep 10
45     done
46 }
47 main

IPddos:

 1 #########################################################################
 2 #    File Name: namp.sh
 3 #    Author: kingle
 4 #    Mail: kingle122@vip.qq.com 
 5 #    Created Time: Mon 06 Aug 2018 04:17:12 PM CST
 6 #########################################################################
 7 #!/bin/bash
 8 file=$1
 9 JudgeExt(){
10     if expr "$1" : ".*\.log" &>/dev/null
11     then
12     :
13     else 
14     echo $"usage:$0 *.log"
15     exit 1
16 fi
17 }
18 IpCount(){
19 grep "ESTABLISHED" $1|awk -F "[ :]+" '{ ++S[$(NF-3)]}END {for(key in S)print S[key],key}'|sort -rn -k1|head -5 >/tmp/tmp.log
20 }
21 ipt (){
22     local ip=$1
23     if [ `iptables -L -n|grep "$ip"|wc -l` -lt 1 ]
24     then 
25     iptables -I INPUT -s $ip -j DROP 
26     echo "$line is dropped" >>/tmp/droplist_$(date +%F).log
27 fi
28 }
29 main(){
30     JudgeExt $file
31     while true
32     do
33         IpCount $file
34         while read line
35         do 
36             ip=`echo $line |awk `{print $2}``
37             count=`echo $line|awk '{print $1}'`
38             if [ $count -gt 3 ]
39             then 
40             ipt $ip
41             fi
42         done</tmp/tmp.log
43         sleep 10
44     done
45 }
46 main

 

posted on 2018-08-06 16:36  kingle-l  阅读(222)  评论(0编辑  收藏  举报

levels of contents