SweetEriri

常用脚本

可以创建一个用户,只能在自己的目录下玩耍。

# !/bin/bash

# Script to add a user to Linux system

function generate_pass() { MATRIX="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" LENGTH=$1 while [ "${n:=1}" -le "$LENGTH" ] do PASS="$PASS$Extra open brace or missing close brace{MATRIX:$(($RANDOM%${#MATRIX})):1}" let n+=1 done echo "$PASS" }

username=$1

if [ -z $username ];then echo "username is empty" exit 1 fi

password=$(generate_pass 6)

if [ $Missing superscript or subscript argument(id -u) -eq 0 ]; then egrep "^$username" /etc/passwd >/dev/null if [ $? -eq 0 ]; then echo "$username exists!" exit 1 else pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) useradd -m -p $pass $username

# record

time=$(date "+%Y-%m-%d-%H-%M-%S") echo "create username $username with password $password at $time" >> user_account.txt [ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!" fi else echo "Only root may add a user to the system" exit 2 fi

批量生成xshell连接

#!/bin/bash
#
for ip in `cat ip.txt`
do
cp 172.81.251.179.xsh ./$ip.xsh
sed -i -e 's/xxx.xx.xxx.xxx/'$ip'/' ./${ip}.xsh
#vim -c ":%s/xxx.xx.xxx.xxx/$ip/g" -c ":x" ./${ip}.xsh
done

JDK安装

#!/bin/bash
Down(){
    mv ./jdk-8u161-linux-x64.tar.gz /usr/local/ && tar -xzvf /usr/local/jdk-8u161-linux-x64.tar.gz -C /usr/local/ && sleep 5
}
Env_jdk(){
    mv /usr/local/jdk1.8.0_161 /usr/local/java
    echo '#2018.3.23
export JAVA_HOME=/usr/local/java
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH '>>/etc/profile

}
Down
Env_jdk
chown -R root:root /usr/local/java/
source /etc/profile && javac -version
echo $?
rm -rf /tmp/jdk.sh && rm -rf /usr/local/jdk-8u161-linux-x64.tar.gz
source /etc/profile && javac -version

RabbitMQ查询

#!/bin/env python

# -*- coding: UTF-8 -*-

import sys, urllib2, base64, json, re,time
ip = " "
keys = ('messages_ready',)
def GetRabbitmqData():
        request = urllib2.Request("http://%s:15672/api/queues" % ip)
        base64string = base64.b64encode('guest:guest')
        request.add_header("Authorization", "Basic %s" % base64string)
        result = urllib2.urlopen(request)
        data = json.loads(result.read())
        return data
data=GetRabbitmqData()
#print data
for queue in data:
    try:
        print "消费者数量:",queue['consumers'],"队列:",queue['name'],"消息积压数:",int(queue[keys[0]])
    except:
        pass

进程状态

#!/bin/bash

nginx(){
ps aux|grep "nginx"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$Extra close brace or missing open brace6}; END{print sum*1000}'
}
nginxcpu(){
    ps aux|grep "nginx"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$3}; END{print sum}'
}
sshd(){
    ps aux|grep "sshd"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$Extra close brace or missing open brace6}; END{print sum*1000}'
}
sshdcpu(){
    ps aux|grep "sshd"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$3}; END{print sum}'
}
mysql(){
    ps aux|grep "mysql"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$Extra close brace or missing open brace6}; END{print sum*1000}' 
}
mysqlcpu(){
    ps aux|grep "mysql"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$3}; END{print sum}'
}
vsftp(){
    ps aux|grep "vsftp"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$Extra close brace or missing open brace6}; END{print sum*1000}'
}
vsftpcpu(){
    ps aux|grep "vsftp"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$3}; END{print sum}'
}
 zabbix_agent(){
    ps aux|grep "zabbix_agent"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$Extra close brace or missing open brace6}; END{print sum*1000}'
}
zabbix_agentcpu(){
    ps aux|grep "zabbix_agent"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$3}; END{print sum}'
}
case "$1" in
nginx)
nginx
;;
nginxcpu)
nginxcpu
;;
sshd)
sshd
;;
sshdcpu)
sshdcpu
;;
mysql)
mysql
;;
mysqlcpu)
mysqlcpu
;;
vsftp)
vsftp
;;
vsftpcpu)
vs
ftpcpu
;;
zabbix_agent)
zabbix_agent
;;
zabbix_agentcpu)
zabbix_agentcpu
;;
*)
echo "Usage: $0 {nginx|nginxcpu|sshd|sshdcpu|mysql|mysqlcpu|vsftp|vsftpcpu|zabbix_agent|zabbix_agentcpu|:}"
;;
esac

发表评论

    暂无评论