shell腳本小計

取出本機IPphp

IP=`/sbin/ifconfig|grep -v 127.0.0.1|sed -n '/inet addr/s/^[^:]*:\([0-9.]\{7,15\}\) .*/\1/p'`bash

取出隨機碼前10位並MD5,用於作密碼
PASSD=`cat /dev/urandom | head -n 10 | md5sum | head -c 10`dom

檢查本網段可ping通的主機
#!/bin/bash
for ip in 'seq 1 254';
do
    ping -c 1 192.168.1.$ip > /dev/null 2>&1
    if [ $? -eq 0 ];then
        echo 192.168.1.$ip UP
    else
        echo 192.168.1.$ip DOWN
    fi
donecurl

#!/bin/sh
#逐行讀取文件並在另外一個文件中比對php-fpm

for i in `cat userid.txt`
do 
    num=`grep -c "$i" ./log-2017-05-21`
    if [ $num -eq 0 ];
    then
        echo "$i" >> user.txt
    fi
doneurl


#!/bin/bash
#重啓php-fpm服務rest

while
do
    URL="http://127.0.0.1"
    RESULT=`curl -m 10 -I -s $URL | grep "HTTP/1.1 502"
    if [ -n "$RESULT"]; then
        /etc/init.d/php-fpm restart
    fi
done
 進程

#登陸後運行命令並顯示 vi .bash_profile添加以下
LOGIN_USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`ip

echo -e "\033[31m歡迎登錄 $HOSTNAME , 您的IP爲:$LOGIN_USER_IP \033[0m"md5

echo -e "\033[32m當前磁盤使用狀況: \033[0m"
df -hP

echo -e "\033[32m當前TCP鏈接數統計: \033[0m"
ss -tan|awk 'NR>1 {++s[$1]} END {for (k in s) print k,s[k]}'

echo -e "\033[32m當前系統負載: \033[0m"
uptime

#! /bin/sh
#兩秒執行一次殺死進程
setp=2
for (( i = 0; i < 60; i=(i+step) )); do  
    ps auxf | grep -v grep | grep "wnTKYg" | awk '{print $2}' |xargs kill -9  
    sleep $step  
done  

if [ ! -f "/tmp/wnTKYg" ]; then
        rm -rf /tmp/wnTKYg
fi

* * * * * /bin/sh /root/kill.sh

相關文章
相關標籤/搜索