update scripts and docs

pull/11/head
Zhang Peng 2019-10-29 18:22:19 +08:00
parent b3290172d3
commit 74a1b7fb2f
262 changed files with 3523 additions and 3845 deletions

View File

@ -4,9 +4,9 @@
> >
> 📖 [电子书](https://dunwu.github.io/linux-tutorial/) | [电子书(国内)](http://turnon.gitee.io/linux-tutorial/) > 📖 [电子书](https://dunwu.github.io/linux-tutorial/) | [电子书(国内)](http://turnon.gitee.io/linux-tutorial/)
| :wrench: | :shell: | :memo: | 📚 | | 🛠 | 🐚 | 📝 | 📚 |
| :-------------------: | :-------------------: | :---------------: | :-------------------: | | :-------------------: | :-----------------------: | :-----------: | :-------------------: |
| [软件运维](#软件运维) | [运维和脚本](#运维和脚本) | [知识点](#知识点) | [学习资源](#学习资源) | | [软件运维](#软件运维) | [Shell 脚本](#Shell-脚本) | [教程](#教程) | [学习资源](#学习资源) |
## 软件运维 ## 软件运维
@ -37,21 +37,21 @@
- [Mongodb 运维](docs/linux/soft/mongodb-ops.md) - [Mongodb 运维](docs/linux/soft/mongodb-ops.md)
- [Redis 运维](docs/linux/soft/redis-ops.md) - [Redis 运维](docs/linux/soft/redis-ops.md)
## 运维和脚本 ## Shell 脚本
- [系统运维脚本集合](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/sys) ### Shell 脚本大全
- [工具脚本集合](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/soft)
- [Vim 应用指南](docs/linux/ops/vim.md)
- [Zsh 应用指南](docs/linux/ops/zsh.md)
- [Shell 教程](docs/linux/ops/shell.md)
- [Python 教程](docs/linux/ops/python.md)
- [Systemd 入门教程](docs/linux/ops/systemd.md)
> 提供一键式运维、配置软件脚本 **Shell 脚本大全** 精心收集、整理了 Linux 环境下的常见 Shell 脚本操作片段。
## 知识点 源码:[**Shell 脚本大全**](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/sys)
### Linux ### CentOS 常规操作运维脚本集合
本人作为一名 Java 后端,苦于经常在 CentOS 环境上开荒虚拟机。为提高效率,写了一套 Shell 脚本,提供如下功能:安装常用 lib 库、命令工具、设置 DNS、NTP、配置国内 yum 源、一键安装常用软件等。
源码:[**CentOS 常规操作运维脚本集合**](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/sys)
## 教程
- [Linux 命令教程](docs/linux/cli/README.md) - [Linux 命令教程](docs/linux/cli/README.md)
- [查看 Linux 命令帮助信息](docs/linux/cli/查看Linux命令帮助信息.md) - [查看 Linux 命令帮助信息](docs/linux/cli/查看Linux命令帮助信息.md)
@ -63,23 +63,23 @@
- [Linux 网络管理](docs/linux/cli/Linux网络管理.md) - [Linux 网络管理](docs/linux/cli/Linux网络管理.md)
- [Linux 硬件管理](docs/linux/cli/Linux硬件管理.md) - [Linux 硬件管理](docs/linux/cli/Linux硬件管理.md)
- [Linux 软件管理](docs/linux/cli/Linux硬件管理.md) - [Linux 软件管理](docs/linux/cli/Linux硬件管理.md)
- [Linux 运维](docs/linux/ops/README.md)
- [linux 典型运维应用](docs/linux/ops/linux典型运维应用.md)
- [samba 使用详解](docs/linux/ops/samba使用详解.md)
### Docker
- [Docker 教程](docs/docker) - [Docker 教程](docs/docker)
- [Docker 应用指南](docs/docker/docker.md) - [Docker 应用指南](docs/docker/docker.md)
- [Docker Cheat Sheet](docs/docker/docker-cheat-sheet.md) - [Docker Cheat Sheet](docs/docker/docker-cheat-sheet.md)
### Git
- [Git 教程](docs/git/README.md) - [Git 教程](docs/git/README.md)
- [Git 快速指南](docs/git/git-quickstart.md) - [Git 快速指南](docs/git/git-quickstart.md)
- [Git 配置](docs/git/git-configuration.md) - [Git 配置](docs/git/git-configuration.md)
- [git-flow 工作流](docs/git/git-flow.md) - [git-flow 工作流](docs/git/git-flow.md)
- [Git 常见问题](docs/git/git-faq.md) - [Git 常见问题](docs/git/git-faq.md)
- 运维
- [linux 典型运维应用](docs/linux/ops/linux典型运维应用.md)
- [samba 使用详解](docs/linux/ops/samba使用详解.md)
- [Systemd 教程](docs/linux/ops/systemd.md)
- 脚本
- [Vim 应用指南](docs/linux/ops/vim.md)
- [Zsh 应用指南](docs/linux/ops/zsh.md)
- [Shell 教程](docs/linux/ops/shell.md)
- [Python 教程](docs/linux/ops/python.md)
## 学习资源 ## 学习资源

View File

@ -1,4 +1,4 @@
# Dunwu Shell 运维脚本 # CentOS 常规操作运维脚本集合
> **本项目脚本代码用于在 [CentOS](https://www.centos.org/) 机器上安装常用命令工具或开发软件。** > **本项目脚本代码用于在 [CentOS](https://www.centos.org/) 机器上安装常用命令工具或开发软件。**

View File

@ -38,7 +38,7 @@ packageJavaOpts() {
JAVA_OPTS="${JAVA_OPTS} -XX:HeapDumpPath=${LOG_PATH}/${APP_NAME}.heapdump.hprof" JAVA_OPTS="${JAVA_OPTS} -XX:HeapDumpPath=${LOG_PATH}/${APP_NAME}.heapdump.hprof"
# JMX OPTS # JMX OPTS
IP=`ip addr|grep "inet "|grep -v 127.0.0.1|awk '{print $2}'|cut -d/ -f1` IP=`ip addr | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}' | cut -d/ -f1`
JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote=true" JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote=true"
JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false" JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
JAVA_OPTS="${JAVA_OPTS} -Djava.rmi.server.hostname=${IP} -Dcom.sun.management.jmxremote.port=18889" JAVA_OPTS="${JAVA_OPTS} -Djava.rmi.server.hostname=${IP} -Dcom.sun.management.jmxremote.port=18889"
@ -65,18 +65,18 @@ checkStarted() {
main() { main() {
case "${oper}" in case "${oper}" in
start ) start)
startServer startServer
;; ;;
stop ) stop)
stopServer stopServer
;; ;;
restart ) restart)
stopServer stopServer
sleep 5 sleep 5
startServer startServer
;; ;;
* ) *)
echo "Invalid oper: ${oper}." echo "Invalid oper: ${oper}."
exit 1 exit 1
esac esac
@ -86,7 +86,7 @@ main() {
stopServer() { stopServer() {
echo -n "stopping server: " echo -n "stopping server: "
if checkStarted ;then if checkStarted; then
kill -9 ${pid} kill -9 ${pid}
printf "${GREEN}\n${APP_NAME} is stopped.${RESET}\n" printf "${GREEN}\n${APP_NAME} is stopped.${RESET}\n"
else else
@ -96,7 +96,7 @@ stopServer() {
startServer() { startServer() {
printf "${BLUE}starting ${APP_NAME}...${RESET}\n" printf "${BLUE}starting ${APP_NAME}...${RESET}\n"
if checkStarted ;then if checkStarted; then
printf "${YELLOW}[WARN] ${APP_NAME} already started!${RESET}\n" printf "${YELLOW}[WARN] ${APP_NAME} already started!${RESET}\n"
printf "PID: ${pid}\n" printf "PID: ${pid}\n"
exit 1 exit 1
@ -121,7 +121,7 @@ LOG_PATH=${ROOT_DIR}/../logs
mkdir -p ${LOG_PATH} mkdir -p ${LOG_PATH}
declare -a serial declare -a serial
serial=(start stop restart) serial=( start stop restart )
echo -n "请选择操作可选值start|stop|restart" echo -n "请选择操作可选值start|stop|restart"
read oper read oper
if ! echo "${serial[@]}" | grep -q ${oper}; then if ! echo "${serial[@]}" | grep -q ${oper}; then
@ -131,7 +131,7 @@ fi
if [[ ${oper} == "start" ]] || [[ "${oper}" == "restart" ]]; then if [[ ${oper} == "start" ]] || [[ "${oper}" == "restart" ]]; then
declare -a serial2 declare -a serial2
serial2=(prod dev test) serial2=( prod dev test )
echo -n "选择 profile可选值prod|dev|test" echo -n "选择 profile可选值prod|dev|test"
read profile read profile
if ! echo "${serial2[@]}" | grep -q ${profile}; then if ! echo "${serial2[@]}" | grep -q ${profile}; then
@ -140,7 +140,7 @@ if [[ ${oper} == "start" ]] || [[ "${oper}" == "restart" ]]; then
fi fi
declare -a serial3 declare -a serial3
serial3=(on off) serial3=( on off )
echo -n "是否启动 debug 模式可选值on|off" echo -n "是否启动 debug 模式可选值on|off"
read debug read debug
if ! echo "${serial3[@]}" | grep -q ${debug}; then if ! echo "${serial3[@]}" | grep -q ${debug}; then

View File

@ -14,26 +14,26 @@ RESET="$(tput sgr0)"
# 打印头部信息 # 打印头部信息
printHeadInfo() { printHeadInfo() {
printf "${BLUE}\n" printf "${BLUE}\n"
cat << EOF cat << EOF
################################################################################### ###################################################################################
# 欢迎使用 Dunwu Shell 运维脚本 # 欢迎使用 Dunwu Shell 运维脚本
# 适用于 Linux CentOS 环境 # 适用于 Linux CentOS 环境
# @author: Zhang Peng # @author: Zhang Peng
################################################################################### ###################################################################################
EOF EOF
printf "${RESET}\n" printf "${RESET}\n"
} }
# 打印尾部信息 # 打印尾部信息
printFootInfo() { printFootInfo() {
printf "${BLUE}\n" printf "${BLUE}\n"
cat << EOF cat << EOF
################################################################################### ###################################################################################
# 脚本执行结束,感谢使用! # 脚本执行结束,感谢使用!
################################################################################### ###################################################################################
EOF EOF
printf "${RESET}\n" printf "${RESET}\n"
} }
# 检查操作系统环境 # 检查操作系统环境

View File

@ -63,4 +63,5 @@ main() {
fi fi
} }
######################################## MAIN ########################################
main main

View File

@ -29,22 +29,22 @@ main() {
do do
case ${item} in case ${item} in
"替换yum镜像") "替换yum镜像")
sh ${root}/sys/change-yum-repo.sh sh ${path}/sys/change-yum-repo.sh
main ;; main ;;
"安装基本的命令工具") "安装基本的命令工具")
sh ${root}/sys/install-tools.sh sh ${path}/sys/install-tools.sh
main ;; main ;;
"安装常用libs") "安装常用libs")
sh ${root}/sys/install-libs.sh sh ${path}/sys/install-libs.sh
main ;; main ;;
"系统配置") "系统配置")
sh ${root}/sys/sys-settings.sh ${root}/sys sh ${path}/sys/sys-settings.sh ${path}/sys
main ;; main ;;
"全部执行") "全部执行")
sh ${root}/sys/change-yum-repo.sh sh ${path}/sys/change-yum-repo.sh
sh ${root}/sys/install-tools.sh sh ${path}/sys/install-tools.sh
sh ${root}/sys/install-libs.sh sh ${path}/sys/install-libs.sh
sh ${root}/sys/sys-settings.sh ${root}/sys sh ${path}/sys/sys-settings.sh ${path}/sys
printf "${GREEN}执行完毕,退出。${RESET}\n" ;; printf "${GREEN}执行完毕,退出。${RESET}\n" ;;
"退出") "退出")
exit 0 ;; exit 0 ;;
@ -57,5 +57,5 @@ main() {
} }
######################################## MAIN ######################################## ######################################## MAIN ########################################
root=$(pwd) path=$(pwd)
main main

View File

@ -1,6 +1,6 @@
worker_processes 1; worker_processes 1;
#error_log logs/error.log; error_log logs/error.log;
#error_log logs/error.log notice; #error_log logs/error.log notice;
#error_log logs/error.log info; #error_log logs/error.log info;
pid /usr/local/nginx/logs/nginx.pid; pid /usr/local/nginx/logs/nginx.pid;
@ -10,13 +10,17 @@ events {
} }
http { http {
include mime.types;
include conf.d/*.conf;
default_type application/octet-stream; default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" ' '$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/nginx-http-access.log; #access_log logs/nginx-http-access.log;
sendfile on; sendfile on;
rewrite_log on;
keepalive_timeout 65; keepalive_timeout 65;
client_max_body_size 20m; client_max_body_size 20m;
@ -30,7 +34,4 @@ http {
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; proxy_set_header Connection "upgrade";
include mime.types;
include conf/*.conf;
} }

View File

@ -1,12 +0,0 @@
port 6381
bind 0.0.0.0
daemonize yes
cluster-enabled yes
cluster-config-file /opt/redis/redis-5.0.4/cluster/6381/6381.conf
cluster-node-timeout 10000
appendonly yes
dir /opt/redis/redis-5.0.4/cluster/6381
pidfile /var/run/redis-cluster/redis-6381.pid
logfile /opt/redis/redis-5.0.4/cluster/6381/6381.log

View File

@ -1,12 +0,0 @@
port 6382
bind 0.0.0.0
daemonize yes
cluster-enabled yes
cluster-config-file /opt/redis/redis-5.0.4/cluster/6382/6382.conf
cluster-node-timeout 10000
appendonly yes
dir /opt/redis/redis-5.0.4/cluster/6382
pidfile /var/run/redis-cluster/redis-6382.pid
logfile /opt/redis/redis-5.0.4/cluster/6382/6382.log

View File

@ -1,12 +0,0 @@
port 6383
bind 0.0.0.0
daemonize yes
cluster-enabled yes
cluster-config-file /opt/redis/redis-5.0.4/cluster/6383/6383.conf
cluster-node-timeout 10000
appendonly yes
dir /opt/redis/redis-5.0.4/cluster/6383
pidfile /var/run/redis-cluster/redis-6383.pid
logfile /opt/redis/redis-5.0.4/cluster/6383/6383.log

View File

@ -1,12 +0,0 @@
port 6384
bind 0.0.0.0
daemonize yes
cluster-enabled yes
cluster-config-file /opt/redis/redis-5.0.4/cluster/6384/6384.conf
cluster-node-timeout 10000
appendonly yes
dir /opt/redis/redis-5.0.4/cluster/6384
pidfile /var/run/redis-cluster/redis-6384.pid
logfile /opt/redis/redis-5.0.4/cluster/6384/6384.log

View File

@ -1,12 +0,0 @@
port 6385
bind 0.0.0.0
daemonize yes
cluster-enabled yes
cluster-config-file /opt/redis/redis-5.0.4/cluster/6385/6385.conf
cluster-node-timeout 10000
appendonly yes
dir /opt/redis/redis-5.0.4/cluster/6385
pidfile /var/run/redis-cluster/redis-6385.pid
logfile /opt/redis/redis-5.0.4/cluster/6385/6385.log

View File

@ -1,12 +0,0 @@
port 6386
bind 0.0.0.0
daemonize yes
cluster-enabled yes
cluster-config-file /opt/redis/redis-5.0.4/cluster/6386/6386.conf
cluster-node-timeout 10000
appendonly yes
dir /opt/redis/redis-5.0.4/cluster/6386
pidfile /var/run/redis-cluster/redis-6386.pid
logfile /opt/redis/redis-5.0.4/cluster/6386/6386.log

View File

@ -1,7 +0,0 @@
/opt/redis/redis-5.0.4/src/redis-server /opt/redis/redis-5.0.4/cluster/6381/redis.conf
/opt/redis/redis-5.0.4/src/redis-server /opt/redis/redis-5.0.4/cluster/6382/redis.conf
/opt/redis/redis-5.0.4/src/redis-server /opt/redis/redis-5.0.4/cluster/6383/redis.conf
/opt/redis/redis-5.0.4/src/redis-server /opt/redis/redis-5.0.4/cluster/6384/redis.conf
/opt/redis/redis-5.0.4/src/redis-server /opt/redis/redis-5.0.4/cluster/6385/redis.conf
/opt/redis/redis-5.0.4/src/redis-server /opt/redis/redis-5.0.4/cluster/6386/redis.conf

View File

@ -0,0 +1,12 @@
port 6381
bind 0.0.0.0
daemonize yes
cluster-enabled yes
cluster-config-file /usr/local/redis/cluster/6381/6381.conf
cluster-node-timeout 10000
appendonly yes
dir /usr/local/redis/cluster/6381
pidfile /var/run/redis/redis-6381.pid
logfile /usr/local/redis/cluster/6381/6381.log

View File

@ -0,0 +1,12 @@
port 6382
bind 0.0.0.0
daemonize yes
cluster-enabled yes
cluster-config-file /usr/local/redis/cluster/6382/6382.conf
cluster-node-timeout 10000
appendonly yes
dir /usr/local/redis/cluster/6382
pidfile /var/run/redis/redis-6382.pid
logfile /usr/local/redis/cluster/6382/6382.log

View File

@ -0,0 +1,12 @@
port 6383
bind 0.0.0.0
daemonize yes
cluster-enabled yes
cluster-config-file /usr/local/redis/cluster/6383/6383.conf
cluster-node-timeout 10000
appendonly yes
dir /usr/local/redis/cluster/6383
pidfile /var/run/redis/redis-6383.pid
logfile /usr/local/redis/cluster/6383/6383.log

View File

@ -0,0 +1,12 @@
port 6384
bind 0.0.0.0
daemonize yes
cluster-enabled yes
cluster-config-file /usr/local/redis/cluster/6384/6384.conf
cluster-node-timeout 10000
appendonly yes
dir /usr/local/redis/cluster/6384
pidfile /var/run/redis/redis-6384.pid
logfile /usr/local/redis/cluster/6384/6384.log

View File

@ -0,0 +1,12 @@
port 6385
bind 0.0.0.0
daemonize yes
cluster-enabled yes
cluster-config-file /usr/local/redis/cluster/6385/6385.conf
cluster-node-timeout 10000
appendonly yes
dir /usr/local/redis/cluster/6385
pidfile /var/run/redis/redis-6385.pid
logfile /usr/local/redis/cluster/6385/6385.log

View File

@ -0,0 +1,12 @@
port 6386
bind 0.0.0.0
daemonize yes
cluster-enabled yes
cluster-config-file /usr/local/redis/cluster/6386/6386.conf
cluster-node-timeout 10000
appendonly yes
dir /usr/local/redis/cluster/6386
pidfile /var/run/redis/redis-6386.pid
logfile /usr/local/redis/cluster/6386/6386.log

View File

@ -0,0 +1,104 @@
#!/usr/bin/env bash
# ---------------------------------------------------------------------------------
# 控制台颜色
BLACK="\033[1;30m"
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
PURPLE="\033[1;35m"
CYAN="\033[1;36m"
RESET="$(tput sgr0)"
# ---------------------------------------------------------------------------------
printf "${BLUE}\n"
cat << EOF
###################################################################################
# Redis 集群控制脚本
# @system: 适用于 CentOS7+
# @author: Zhang Peng
###################################################################################
EOF
printf "${RESET}\n"
# Settings
PORT=6380
NODES=6
ENDPORT=$((PORT + NODES))
TIMEOUT=2000
REPLICAS=0
PATH="/usr/local/redis"
######################################## MAIN ########################################
printf "${PURPLE}\n"
printf "Usage: $0 [start|create|stop|watch|tail|clean]\n"
printf "start -- Launch Redis Cluster instances.\n"
printf "create -- Create a cluster using redis-cli --cluster create.\n"
printf "stop -- Stop Redis Cluster instances.\n"
printf "watch -- Show CLUSTER NODES output (first 30 lines) of first node.\n"
printf "tail <id> -- Run tail -f of instance at base port + ID.\n"
printf "clean -- Remove all instances data, logs, configs.\n"
printf "clean-logs -- Remove just instances logs.\n"
printf "${RESET}\n"
case $1 in
"start")
while [[ $((PORT < ENDPORT)) != "0" ]]; do
PORT=$((PORT + 1))
echo "Starting $PORT"
if [[ -e "${PATH}/cluster/${PORT}/redis.conf" ]]; then
${PATH}/src/redis-server "${PATH}/cluster/${PORT}/redis.conf"
fi
done
;;
"create")
HOSTS=""
while [[ $((PORT < ENDPORT)) != "0" ]]; do
PORT=$((PORT + 1))
HOSTS="$HOSTS 127.0.0.1:$PORT"
done
${PATH}/src/redis-cli --cluster create $HOSTS --cluster-replicas $REPLICAS
;;
"stop")
while [[ $((PORT < ENDPORT)) != "0" ]]; do
PORT=$((PORT + 1))
echo "Stopping $PORT"
${PATH}/src/redis-cli -p $PORT shutdown nosave
done
;;
"watch")
PORT=$((PORT + 1))
while [[ 1 ]]; do
clear
date
${PATH}/src/redis-cli -p $PORT cluster nodes | head -30
sleep 1
done
;;
"tail")
INSTANCE=$2
PORT=$((PORT + INSTANCE))
tail -f ${PORT}.log
;;
"call")
while [[ $((PORT < ENDPORT)) != "0" ]]; do
PORT=$((PORT + 1))
${PATH}/src/redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9
done
;;
"clean")
rm -rf **/*.log
rm -rf **/appendonly*.aof
rm -rf **/dump*.rdb
rm -rf **/nodes*.conf
;;
"clean-logs")
rm -rf **/*.log
;;
"exit")
printf "${RED}Invalid option!${RESET}\n"
main
exit 0
;;
esac

View File

@ -1,102 +0,0 @@
#!/bin/bash
# Settings
PORT=6380
TIMEOUT=2000
NODES=6
REPLICAS=1
# You may want to put the above config parameters into config.sh in order to
# override the defaults without modifying this script.
if [ -a config.sh ]
then
source "config.sh"
fi
# Computed vars
ENDPORT=$((PORT+NODES))
if [ "$1" == "start" ]
then
while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1))
echo "Starting $PORT"
/opt/redis/redis-5.0.4/src/redis-server /opt/redis/redis-5.0.4/cluster/${PORT}/redis.conf
done
exit 0
fi
if [ "$1" == "create" ]
then
HOSTS=""
while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1))
HOSTS="$HOSTS 127.0.0.1:$PORT"
done
/opt/redis/redis-5.0.4/src/redis-cli --cluster create $HOSTS --cluster-replicas $REPLICAS
exit 0
fi
if [ "$1" == "stop" ]
then
while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1))
echo "Stopping $PORT"
/opt/redis/redis-5.0.4/src/redis-cli -p $PORT shutdown nosave
done
exit 0
fi
if [ "$1" == "watch" ]
then
PORT=$((PORT+1))
while [ 1 ]; do
clear
date
/opt/redis/redis-5.0.4/src/redis-cli -p $PORT cluster nodes | head -30
sleep 1
done
exit 0
fi
if [ "$1" == "tail" ]
then
INSTANCE=$2
PORT=$((PORT+INSTANCE))
tail -f ${PORT}.log
exit 0
fi
if [ "$1" == "call" ]
then
while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1))
/opt/redis/redis-5.0.4/src/redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9
done
exit 0
fi
if [ "$1" == "clean" ]
then
rm -rf *.log
rm -rf appendonly*.aof
rm -rf dump*.rdb
rm -rf nodes*.conf
exit 0
fi
if [ "$1" == "clean-logs" ]
then
rm -rf *.log
exit 0
fi
echo "Usage: $0 [start|create|stop|watch|tail|clean]"
echo "start -- Launch Redis Cluster instances."
echo "create -- Create a cluster using redis-cli --cluster create."
echo "stop -- Stop Redis Cluster instances."
echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node."
echo "tail <id> -- Run tail -f of instance at base port + ID."
echo "clean -- Remove all instances data, logs, configs."
echo "clean-logs -- Remove just instances logs."

View File

@ -155,7 +155,7 @@ supervised no
# #
# Creating a pid file is best effort: if Redis is not able to create it # Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally. # nothing bad happens, the server will start and run normally.
pidfile /var/run/redis_6379.pid pidfile /var/run/redis/redis-6379.pid
# Specify the server verbosity level. # Specify the server verbosity level.
# This can be one of: # This can be one of:

View File

@ -4,7 +4,7 @@ After=network.target
[Service] [Service]
Type=forking Type=forking
PIDFile=/var/run/redis_6379.pid PIDFile=/var/run/redis/redis-6379.pid
ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis.conf ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# auth:kaliarch # auth:kaliarch
# version:v1.0 # version:v1.0

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# auth:kaliarch # auth:kaliarch
# version:v1.0 # version:v1.0

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# auth:kaliarch # auth:kaliarch
# version:v1.0 # version:v1.0

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# auth:kaliarch # auth:kaliarch
# version:v1.0 # version:v1.0

View File

@ -28,10 +28,14 @@ printf "${RESET}"
printf "${GREEN}>>>>>>>> install fastdfs begin.${RESET}\n" printf "${GREEN}>>>>>>>> install fastdfs begin.${RESET}\n"
command -v yum > /dev/null 2>&1 || { printf "${RED}Require yum but it's not installed.${RESET}\n"; command -v yum > /dev/null 2>&1 || {
exit 1; } printf "${RED}Require yum but it's not installed.${RESET}\n";
command -v git > /dev/null 2>&1 || { printf "${RED}Require git but it's not installed.${RESET}\n"; exit 1;
exit 1; } }
command -v git > /dev/null 2>&1 || {
printf "${RED}Require git but it's not installed.${RESET}\n";
exit 1;
}
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
printf "${PURPLE}[Hint]\n" printf "${PURPLE}[Hint]\n"

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# auth:kaliarch # auth:kaliarch
# version:v1.0 # version:v1.0

View File

@ -27,8 +27,10 @@ printf "${RESET}"
printf "${GREEN}>>>>>>>> install jdk8 begin.${RESET}\n" printf "${GREEN}>>>>>>>> install jdk8 begin.${RESET}\n"
command -v yum > /dev/null 2>&1 || { printf "${RED}Require yum but it's not installed.${RESET}\n"; command -v yum > /dev/null 2>&1 || {
exit 1; } printf "${RED}Require yum but it's not installed.${RESET}\n";
exit 1;
}
yum -y install java-1.8.0-openjdk-devel.x86_64 yum -y install java-1.8.0-openjdk-devel.x86_64
java -version java -version

View File

@ -26,8 +26,10 @@ printf "${RESET}"
printf "${GREEN}>>>>>>>> install kafka begin.${RESET}\n" printf "${GREEN}>>>>>>>> install kafka begin.${RESET}\n"
command -v java > /dev/null 2>&1 || { printf "${RED}Require java but it's not installed.${RESET}\n"; command -v java > /dev/null 2>&1 || {
exit 1; } printf "${RED}Require java but it's not installed.${RESET}\n";
exit 1;
}
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
printf "${PURPLE}[Hint]\n" printf "${PURPLE}[Hint]\n"

View File

@ -28,8 +28,10 @@ printf "${RESET}"
printf "${GREEN}>>>>>>>> install maven begin.${RESET}\n" printf "${GREEN}>>>>>>>> install maven begin.${RESET}\n"
command -v java > /dev/null 2>&1 || { printf "${RED}Require java but it's not installed.${RESET}\n"; command -v java > /dev/null 2>&1 || {
exit 1; } printf "${RED}Require java but it's not installed.${RESET}\n";
exit 1;
}
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
printf "${PURPLE}[Hint]\n" printf "${PURPLE}[Hint]\n"

View File

@ -26,12 +26,18 @@ printf "${RESET}"
printf "${GREEN}>>>>>>>> install mysql begin.${RESET}\n" printf "${GREEN}>>>>>>>> install mysql begin.${RESET}\n"
command -v wget > /dev/null 2>&1 || { printf "${RED}Require wget but it's not installed.${RESET}\n"; command -v wget > /dev/null 2>&1 || {
exit 1; } printf "${RED}Require wget but it's not installed.${RESET}\n";
command -v rpm > /dev/null 2>&1 || { printf "${RED}Require rpm but it's not installed.${RESET}\n"; exit 1;
exit 1; } }
command -v yum > /dev/null 2>&1 || { printf "${RED}Require yum but it's not installed.${RESET}\n"; command -v rpm > /dev/null 2>&1 || {
exit 1; } printf "${RED}Require rpm but it's not installed.${RESET}\n";
exit 1;
}
command -v yum > /dev/null 2>&1 || {
printf "${RED}Require yum but it's not installed.${RESET}\n";
exit 1;
}
# 使用 rpm 安装 mysql # 使用 rpm 安装 mysql
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

View File

@ -11,10 +11,14 @@ cat << EOF
EOF EOF
command -v java > /dev/null 2>&1 || { echo >&2 "Require java but it's not installed."; command -v java > /dev/null 2>&1 || {
exit 1; } printf "${RED}Require java but it's not installed.${RESET}\n";
command -v mvn > /dev/null 2>&1 || { echo >&2 "Require mvn but it's not installed."; exit 1;
exit 1; } }
command -v mvn > /dev/null 2>&1 || {
printf "${RED}Require mvn but it's not installed.${RESET}\n";
exit 1;
}
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
echo "Usage: sh nacos-install.sh [version] [path]" echo "Usage: sh nacos-install.sh [version] [path]"

View File

@ -27,10 +27,14 @@ printf "${RESET}"
printf "${GREEN}>>>>>>>> install zsh begin.${RESET}\n" printf "${GREEN}>>>>>>>> install zsh begin.${RESET}\n"
command -v yum > /dev/null 2>&1 || { printf "${RED}Require yum but it's not installed.${RESET}\n"; command -v yum > /dev/null 2>&1 || {
exit 1; } printf "${RED}Require yum but it's not installed.${RESET}\n";
command -v git > /dev/null 2>&1 || { printf "${RED}Require git but it's not installed.${RESET}\n"; exit 1;
exit 1; } }
command -v git > /dev/null 2>&1 || {
printf "${RED}Require git but it's not installed.${RESET}\n";
exit 1;
}
# install zsh # install zsh
yum install -y zsh yum install -y zsh

View File

@ -13,25 +13,25 @@ RESET="$(tput sgr0)"
# --------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------
printHeadInfo() { printHeadInfo() {
printf "${BLUE}\n" printf "${BLUE}\n"
cat << EOF cat << EOF
################################################################################### ###################################################################################
# Linux Centos7 系统配置脚本(根据需要选择) # Linux Centos7 系统配置脚本(根据需要选择)
# @author: Zhang Peng # @author: Zhang Peng
################################################################################### ###################################################################################
EOF EOF
printf "${RESET}\n" printf "${RESET}\n"
} }
setLimit() { setLimit() {
cat >> /etc/security/limits.conf << EOF cat >> /etc/security/limits.conf << EOF
* - nofile 65535 * - nofile 65535
* - nproc 65535 * - nproc 65535
EOF EOF
} }
setLang() { setLang() {
cat > /etc/sysconfig/i18n << EOF cat > /etc/sysconfig/i18n << EOF
LANG="zh_CN.UTF-8" LANG="zh_CN.UTF-8"
EOF EOF
} }
@ -63,7 +63,7 @@ setBootMode() {
configIpv4() { configIpv4() {
printf "\n${CYAN}>>>> 配置 IPv4${RESET}\n" printf "\n${CYAN}>>>> 配置 IPv4${RESET}\n"
cat >> /etc/sysctl.conf << EOF cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 2 net.ipv4.tcp_fin_timeout = 2
@ -92,7 +92,7 @@ EOF
closeIpv6() { closeIpv6() {
printf "\n${CYAN}>>>> 关闭 IPv6${RESET}\n" printf "\n${CYAN}>>>> 关闭 IPv6${RESET}\n"
cat > /etc/modprobe.d/ipv6.conf << EOF cat > /etc/modprobe.d/ipv6.conf << EOF
alias net-pf-10 off alias net-pf-10 off
options ipv6 disable=1 options ipv6 disable=1
EOF EOF

View File

@ -1,325 +0,0 @@
#!/usr/bin/env bash
##############################################################################
# console color
C_RESET="$(tput sgr0)"
C_BLACK="\033[1;30m"
C_RED="\033[1;31m"
C_GREEN="\033[1;32m"
C_YELLOW="\033[1;33m"
C_BLUE="\033[1;34m"
C_PURPLE="\033[1;35m"
C_CYAN="\033[1;36m"
C_WHITE="\033[1;37m"
##############################################################################
printf "${C_PURPLE}"
cat << EOF
###################################################################################
# 系统信息检查脚本
# @author: Zhang Peng
###################################################################################
EOF
printf "${C_RESET}"
[[ $(id -u) -gt 0 ]] && echo "请用root用户执行此脚本" && exit 1
sysversion=$(rpm -q centos-release|cut -d- -f3)
double_line="==============================================================="
line="----------------------------------------------"
# 打印头部信息
printHeadInfo() {
cat << EOF
+---------------------------------------------------------------------------------+
| 欢迎使用 【系统信息检查脚本】 |
| @author: Zhang Peng |
+---------------------------------------------------------------------------------+
EOF
}
# 打印尾部信息
printFootInfo() {
cat << EOF
+---------------------------------------------------------------------------------+
| 脚本执行结束,感谢使用! |
+---------------------------------------------------------------------------------+
EOF
}
options=("获取系统信息" "获取服务信息" "获取CPU信息" "获取系统网络信息" "获取系统内存信息" "获取系统磁盘信息" "获取CPU/内存占用TOP10" "获取系统用户信息" "输出所有信息" "退出")
printMenu() {
printf "${C_BLUE}"
printf "主菜单:\n"
for i in "${!options[@]}"; do
index=`expr ${i} + 1`
val=`expr ${index} % 2`
printf "\t(%02d) %-30s" "${index}" "${options[$i]}"
if [[ ${val} -eq 0 ]]; then
printf "\n"
fi
done
printf "${C_BLUE}请输入需要执行的指令:\n"
printf "${C_RESET}"
}
# 获取系统信息
get_systatus_info() {
sys_os=$(uname -o)
sys_release=$(cat /etc/redhat-release)
sys_kernel=$(uname -r)
sys_hostname=$(hostname)
sys_selinux=$(getenforce)
sys_lang=$(echo $LANG)
sys_lastreboot=$(who -b | awk '{print $3,$4}')
sys_runtime=$(uptime |awk '{print $3,$4}'|cut -d, -f1)
sys_time=$(date)
sys_load=$(uptime |cut -d: -f5)
cat << EOF
【系统信息】
系统: ${sys_os}
发行版本: ${sys_release}
系统内核: ${sys_kernel}
主机名: ${sys_hostname}
selinux状态: ${sys_selinux}
系统语言: ${sys_lang}
系统当前时间: ${sys_time}
系统最后重启时间: ${sys_lastreboot}
系统运行时间: ${sys_runtime}
系统负载: ${sys_load}
EOF
}
# 获取CPU信息
get_cpu_info() {
Physical_CPUs=$(grep "physical id" /proc/cpuinfo| sort | uniq | wc -l)
Virt_CPUs=$(grep "processor" /proc/cpuinfo | wc -l)
CPU_Kernels=$(grep "cores" /proc/cpuinfo|uniq| awk -F ': ' '{print $2}')
CPU_Type=$(grep "model name" /proc/cpuinfo | awk -F ': ' '{print $2}' | sort | uniq)
CPU_Arch=$(uname -m)
cat << EOF
【CPU信息】
物理CPU个数:$Physical_CPUs
逻辑CPU个数:$Virt_CPUs
每CPU核心数:$CPU_Kernels
CPU型号:$CPU_Type
CPU架构:$CPU_Arch
EOF
}
# 获取服务信息
get_service_info() {
port_listen=$(netstat -lntup|grep -v "Active Internet")
kernel_config=$(sysctl -p 2>/dev/null)
if [[ ${sysversion} -gt 6 ]];then
service_config=$(systemctl list-unit-files --type=service --state=enabled|grep "enabled")
run_service=$(systemctl list-units --type=service --state=running |grep ".service")
else
service_config=$(/sbin/chkconfig | grep -E ":on|:启用" |column -t)
run_service=$(/sbin/service --status-all|grep -E "running")
fi
cat << EOF
【服务信息】
${service_config}
${line}
运行的服务:
${run_service}
${line}
监听端口:
${port_listen}
${line}
内核参考配置:
${kernel_config}
EOF
}
# 获取系统内存信息
get_mem_info() {
check_mem=$(free -m)
MemTotal=$(grep MemTotal /proc/meminfo| awk '{print $2}') #KB
MemFree=$(grep MemFree /proc/meminfo| awk '{print $2}') #KB
let MemUsed=MemTotal-MemFree
MemPercent=$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf \"%.2f\",$MemUsed*100/$MemTotal}}")
report_MemTotal="$((MemTotal/1024))""MB" #内存总容量(MB)
report_MemFree="$((MemFree/1024))""MB" #内存剩余(MB)
report_MemUsedPercent=$(free | sed -n '2p' | gawk 'x = int(( $3 / $2 ) * 100) {print x}' | sed 's/$/%/')
cat << EOF
【内存信息】
内存总容量(MB): ${report_MemTotal}
内存剩余量(MB):${report_MemFree}
内存使用率: ${report_MemUsedPercent}
EOF
}
# 获取系统网络信息
get_net_info() {
pri_ipadd=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}')
pub_ipadd=$(curl ifconfig.me -s)
gateway=$(ip route | grep default | awk '{print $3}')
mac_info=$(ip link| egrep -v "lo"|grep link|awk '{print $2}')
dns_config=$(egrep -v "^$|^#" /etc/resolv.conf)
route_info=$(route -n)
cat << EOF
【网络信息】
系统公网地址:${pub_ipadd}
系统私网地址:${pri_ipadd}
网关地址:${gateway}
MAC地址:${mac_info}
路由信息:
${route_info}
DNS 信息:
${dns_config}
EOF
}
# 获取系统磁盘信息
get_disk_info() {
disk_info=$(fdisk -l|grep "Disk /dev"|cut -d, -f1)
disk_use=$(df -hTP|awk '$2!="tmpfs"{print}')
disk_percent=$(free | sed -n '2p' | gawk 'x = int(( $3 / $2 ) * 100) {print x}' | sed 's/$/%/')
disk_inode=$(df -hiP|awk '$1!="tmpfs"{print}')
cat << EOF
【磁盘信息】
${disk_info}
磁盘使用: ${disk_use}
磁盘使用百分比: ${disk_percent}
inode信息: ${disk_inode}
EOF
}
# 获取系统用户信息
get_sys_user() {
login_user=$(awk -F: '{if ($NF=="/bin/bash") print $0}' /etc/passwd)
ssh_config=$(egrep -v "^#|^$" /etc/ssh/sshd_config)
sudo_config=$(egrep -v "^#|^$" /etc/sudoers |grep -v "^Defaults")
host_config=$(egrep -v "^#|^$" /etc/hosts)
crond_config=$(for cronuser in /var/spool/cron/* ;do ls ${cronuser} 2>/dev/null|cut -d/ -f5;egrep -v "^$|^#" ${cronuser} 2>/dev/null;echo "";done)
cat << EOF
【用户信息】
系统登录用户:
${login_user}
${line}
ssh 配置信息:
${ssh_config}
${line}
sudo 配置用户:
${sudo_config}
${line}
定时任务配置:
${crond_config}
${line}
hosts 信息:
${host_config}
EOF
}
# 获取CPU/内存占用TOP10
get_process_top_info() {
top_title=$(top -b n1 | head -7 | tail -1)
cpu_top10=$(top -b n1 | head -17 | tail -11)
mem_top10=$(top -b n1 | head -17 | tail -10 | sort -k10 -r)
cat << EOF
【TOP10】
CPU占用TOP10:
${cpu_top10}
内存占用TOP10:
${top_title}
${mem_top10}
EOF
}
show_dead_process() {
printf "僵尸进程:\n"
ps -al | gawk '{print $2,$4}' | grep Z
}
get_all_info() {
get_systatus_info
echo ${double_line}
get_service_info
echo ${double_line}
get_cpu_info
echo ${double_line}
get_net_info
echo ${double_line}
get_mem_info
echo ${double_line}
get_disk_info
echo ${double_line}
get_process_top_info
echo ${double_line}
get_sys_user
}
main() {
while [[ 1 ]]
do
printMenu
read option
local index=$[${option} - 1]
case ${options[${index}]} in
"获取系统信息")
get_systatus_info;;
"获取服务信息")
get_service_info ;;
"获取CPU信息")
get_cpu_info ;;
"获取系统网络信息")
get_net_info ;;
"获取系统内存信息")
get_mem_info ;;
"获取系统磁盘信息")
get_disk_info ;;
"获取CPU/内存占用TOP10")
get_process_top_info ;;
"获取系统用户信息")
get_sys_user ;;
"输出所有信息")
get_all_info > sys.log
printf "${C_GREEN}信息已经输出到 sys.log 中。${C_RESET}\n\n"
;;
"退出")
exit ;;
*)
clear
echo "抱歉,不支持此选项";;
esac
done
}
######################################## MAIN ########################################
printHeadInfo
main
printFootInfo
printf "${C_RESET}"

View File

@ -0,0 +1,328 @@
#!/usr/bin/env bash
##############################################################################
# console color
C_RESET="$(tput sgr0)"
C_BLACK="\033[1;30m"
C_RED="\033[1;31m"
C_GREEN="\033[1;32m"
C_YELLOW="\033[1;33m"
C_BLUE="\033[1;34m"
C_PURPLE="\033[1;35m"
C_CYAN="\033[1;36m"
C_WHITE="\033[1;37m"
##############################################################################
printf "${C_PURPLE}"
cat << EOF
###################################################################################
# 系统信息检查脚本
# @author: Zhang Peng
###################################################################################
EOF
printf "${C_RESET}"
[[ $(id -u) -gt 0 ]] && echo "请用root用户执行此脚本" && exit 1
sysversion=$(rpm -q centos-release | cut -d- -f3)
double_line="==============================================================="
line="----------------------------------------------"
# 打印头部信息
printHeadInfo() {
cat << EOF
+---------------------------------------------------------------------------------+
| 欢迎使用 【系统信息检查脚本】 |
| @author: Zhang Peng |
+---------------------------------------------------------------------------------+
EOF
}
# 打印尾部信息
printFootInfo() {
cat << EOF
+---------------------------------------------------------------------------------+
| 脚本执行结束,感谢使用! |
+---------------------------------------------------------------------------------+
EOF
}
options=( "获取系统信息" "获取服务信息" "获取CPU信息" "获取系统网络信息" "获取系统内存信息" "获取系统磁盘信息" "获取CPU/内存占用TOP10" "获取系统用户信息" "输出所有信息" "退出" )
printMenu() {
printf "${C_BLUE}"
printf "主菜单:\n"
for i in "${!options[@]}"; do
index=`expr ${i} + 1`
val=`expr ${index} % 2`
printf "\t(%02d) %-30s" "${index}" "${options[$i]}"
if [[ ${val} -eq 0 ]]; then
printf "\n"
fi
done
printf "${C_BLUE}请输入需要执行的指令:\n"
printf "${C_RESET}"
}
# 获取系统信息
get_systatus_info() {
sys_os=$(uname -o)
sys_release=$(cat /etc/redhat-release)
sys_kernel=$(uname -r)
sys_hostname=$(hostname)
sys_selinux=$(getenforce)
sys_lang=$(echo $LANG)
sys_lastreboot=$(who -b | awk '{print $3,$4}')
sys_runtime=$(uptime | awk '{print $3,$4}' | cut -d, -f1)
sys_time=$(date)
sys_load=$(uptime | cut -d: -f5)
cat << EOF
【系统信息】
系统: ${sys_os}
发行版本: ${sys_release}
系统内核: ${sys_kernel}
主机名: ${sys_hostname}
selinux状态: ${sys_selinux}
系统语言: ${sys_lang}
系统当前时间: ${sys_time}
系统最后重启时间: ${sys_lastreboot}
系统运行时间: ${sys_runtime}
系统负载: ${sys_load}
EOF
}
# 获取CPU信息
get_cpu_info() {
Physical_CPUs=$(grep "physical id" /proc/cpuinfo | sort | uniq | wc -l)
Virt_CPUs=$(grep "processor" /proc/cpuinfo | wc -l)
CPU_Kernels=$(grep "cores" /proc/cpuinfo | uniq | awk -F ': ' '{print $2}')
CPU_Type=$(grep "model name" /proc/cpuinfo | awk -F ': ' '{print $2}' | sort | uniq)
CPU_Arch=$(uname -m)
cat << EOF
【CPU信息】
物理CPU个数:$Physical_CPUs
逻辑CPU个数:$Virt_CPUs
每CPU核心数:$CPU_Kernels
CPU型号:$CPU_Type
CPU架构:$CPU_Arch
EOF
}
# 获取服务信息
get_service_info() {
port_listen=$(netstat -lntup | grep -v "Active Internet")
kernel_config=$(sysctl -p 2> /dev/null)
if [[ ${sysversion} -gt 6 ]]; then
service_config=$(systemctl list-unit-files --type=service --state=enabled | grep "enabled")
run_service=$(systemctl list-units --type=service --state=running | grep ".service")
else
service_config=$(/sbin/chkconfig | grep -E ":on|:启用" | column -t)
run_service=$(/sbin/service --status-all | grep -E "running")
fi
cat << EOF
【服务信息】
${service_config}
${line}
运行的服务:
${run_service}
${line}
监听端口:
${port_listen}
${line}
内核参考配置:
${kernel_config}
EOF
}
# 获取系统内存信息
get_mem_info() {
check_mem=$(free -m)
MemTotal=$(grep MemTotal /proc/meminfo | awk '{print $2}') #KB
MemFree=$(grep MemFree /proc/meminfo | awk '{print $2}') #KB
let MemUsed=MemTotal-MemFree
MemPercent=$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf \"%.2f\",$MemUsed*100/$MemTotal}}")
report_MemTotal="$((MemTotal/1024))" "MB" #内存总容量(MB)
report_MemFree="$((MemFree/1024))" "MB" #内存剩余(MB)
report_MemUsedPercent=$(free | sed -n '2p' | gawk 'x = int(( $3 / $2 ) * 100) {print x}' | sed 's/$/%/')
cat << EOF
【内存信息】
内存总容量(MB): ${report_MemTotal}
内存剩余量(MB):${report_MemFree}
内存使用率: ${report_MemUsedPercent}
EOF
}
# 获取系统网络信息
get_net_info() {
pri_ipadd=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}')
pub_ipadd=$(curl ifconfig.me -s)
gateway=$(ip route | grep default | awk '{print $3}')
mac_info=$(ip link | egrep -v "lo" | grep link | awk '{print $2}')
dns_config=$(egrep -v "^$|^#" /etc/resolv.conf)
route_info=$(route -n)
cat << EOF
【网络信息】
系统公网地址:${pub_ipadd}
系统私网地址:${pri_ipadd}
网关地址:${gateway}
MAC地址:${mac_info}
路由信息:
${route_info}
DNS 信息:
${dns_config}
EOF
}
# 获取系统磁盘信息
get_disk_info() {
disk_info=$(fdisk -l | grep "Disk /dev" | cut -d, -f1)
disk_use=$(df -hTP | awk '$2!="tmpfs"{print}')
disk_percent=$(free | sed -n '2p' | gawk 'x = int(( $3 / $2 ) * 100) {print x}' | sed 's/$/%/')
disk_inode=$(df -hiP | awk '$1!="tmpfs"{print}')
cat << EOF
【磁盘信息】
${disk_info}
磁盘使用: ${disk_use}
磁盘使用百分比: ${disk_percent}
inode信息: ${disk_inode}
EOF
}
# 获取系统用户信息
get_sys_user() {
login_user=$(awk -F: '{if ($NF=="/bin/bash") print $0}' /etc/passwd)
ssh_config=$(egrep -v "^#|^$" /etc/ssh/sshd_config)
sudo_config=$(egrep -v "^#|^$" /etc/sudoers | grep -v "^Defaults")
host_config=$(egrep -v "^#|^$" /etc/hosts)
crond_config=$(for cronuser in /var/spool/cron/*; do
ls ${cronuser} 2> /dev/null | cut -d/ -f5; egrep -v "^$|^#" ${cronuser} 2> /dev/null;
echo "";
done)
cat << EOF
【用户信息】
系统登录用户:
${login_user}
${line}
ssh 配置信息:
${ssh_config}
${line}
sudo 配置用户:
${sudo_config}
${line}
定时任务配置:
${crond_config}
${line}
hosts 信息:
${host_config}
EOF
}
# 获取CPU/内存占用TOP10
get_process_top_info() {
top_title=$(top -b n1 | head -7 | tail -1)
cpu_top10=$(top -b n1 | head -17 | tail -11)
mem_top10=$(top -b n1 | head -17 | tail -10 | sort -k10 -r)
cat << EOF
【TOP10】
CPU占用TOP10:
${cpu_top10}
内存占用TOP10:
${top_title}
${mem_top10}
EOF
}
show_dead_process() {
printf "僵尸进程:\n"
ps -al | gawk '{print $2,$4}' | grep Z
}
get_all_info() {
get_systatus_info
echo ${double_line}
get_service_info
echo ${double_line}
get_cpu_info
echo ${double_line}
get_net_info
echo ${double_line}
get_mem_info
echo ${double_line}
get_disk_info
echo ${double_line}
get_process_top_info
echo ${double_line}
get_sys_user
}
main() {
while [[ 1 ]]
do
printMenu
read option
local index=$[ ${option} - 1 ]
case ${options[${index}]} in
"获取系统信息")
get_systatus_info ;;
"获取服务信息")
get_service_info ;;
"获取CPU信息")
get_cpu_info ;;
"获取系统网络信息")
get_net_info ;;
"获取系统内存信息")
get_mem_info ;;
"获取系统磁盘信息")
get_disk_info ;;
"获取CPU/内存占用TOP10")
get_process_top_info ;;
"获取系统用户信息")
get_sys_user ;;
"输出所有信息")
get_all_info > sys.log
printf "${C_GREEN}信息已经输出到 sys.log 中。${C_RESET}\n\n"
;;
"退出")
exit ;;
*)
clear
echo "抱歉,不支持此选项" ;;
esac
done
}
######################################## MAIN ########################################
printHeadInfo
main
printFootInfo
printf "${C_RESET}"

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
#mail:xuel@anchnet.com #mail:xuel@anchnet.com
#data:2017/9/7 #data:2017/9/7

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# auth:kaliarch # auth:kaliarch
# func:sys info check # func:sys info check

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# function:自定义rm命令每天晚上定时清理 # function:自定义rm命令每天晚上定时清理

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# #
# Daily_Archive - Archive designated files & directories # Daily_Archive - Archive designated files & directories

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# #
# Hourly_Archive - Every hour create an archive # Hourly_Archive - Every hour create an archive

View File

@ -29,7 +29,7 @@ C_STASHES="$C_YELLOW"
DEBUG=0 DEBUG=0
usage () { usage() {
cat << EOF >&2 cat << EOF >&2
Usage: $0 [-w] [-e] [-f] [--no-X] [DIR] [DEPTH=2] Usage: $0 [-w] [-e] [-f] [--no-X] [DIR] [DEPTH=2]
@ -137,11 +137,11 @@ do
# Do a 'git fetch' if requested # Do a 'git fetch' if requested
if [ "$DO_FETCH" -eq 1 ]; then if [ "$DO_FETCH" -eq 1 ]; then
git --work-tree "$(dirname "$GIT_DIR")" --git-dir "$GIT_DIR" fetch -q >/dev/null git --work-tree "$(dirname "$GIT_DIR")" --git-dir "$GIT_DIR" fetch -q > /dev/null
fi fi
# Refresh the index, or we might get wrong results. # Refresh the index, or we might get wrong results.
git --work-tree "$(dirname "$GIT_DIR")" --git-dir "$GIT_DIR" update-index -q --refresh >/dev/null 2>&1 git --work-tree "$(dirname "$GIT_DIR")" --git-dir "$GIT_DIR" update-index -q --refresh > /dev/null 2>&1
# Find all remote branches that have been checked out and figure out if # Find all remote branches that have been checked out and figure out if
# they need a push or pull. We do this with various tests and put the name # they need a push or pull. We do this with various tests and put the name
@ -153,7 +153,7 @@ do
for REF_HEAD in $(cd "$GIT_DIR/refs/heads" && find . -type 'f' | sed "s/^\.\///"); do for REF_HEAD in $(cd "$GIT_DIR/refs/heads" && find . -type 'f' | sed "s/^\.\///"); do
# Check if this branch is tracking an upstream (local/remote branch) # Check if this branch is tracking an upstream (local/remote branch)
UPSTREAM=$(git --git-dir "$GIT_DIR" rev-parse --abbrev-ref --symbolic-full-name "$REF_HEAD@{u}" 2>/dev/null) UPSTREAM=$(git --git-dir "$GIT_DIR" rev-parse --abbrev-ref --symbolic-full-name "$REF_HEAD@{u}" 2> /dev/null)
EXIT_CODE="$?" EXIT_CODE="$?"
if [ "$EXIT_CODE" -eq 0 ]; then if [ "$EXIT_CODE" -eq 0 ]; then
# Branch is tracking a remote branch. Find out how much behind / # Branch is tracking a remote branch. Find out how much behind /
@ -175,9 +175,9 @@ do
# Check if this branch is a branch off another branch. and if it needs # Check if this branch is a branch off another branch. and if it needs
# to be updated. # to be updated.
REV_LOCAL=$(git --git-dir "$GIT_DIR" rev-parse --verify "$REF_HEAD" 2>/dev/null) REV_LOCAL=$(git --git-dir "$GIT_DIR" rev-parse --verify "$REF_HEAD" 2> /dev/null)
REV_REMOTE=$(git --git-dir "$GIT_DIR" rev-parse --verify "$UPSTREAM" 2>/dev/null) REV_REMOTE=$(git --git-dir "$GIT_DIR" rev-parse --verify "$UPSTREAM" 2> /dev/null)
REV_BASE=$(git --git-dir "$GIT_DIR" merge-base "$REF_HEAD" "$UPSTREAM" 2>/dev/null) REV_BASE=$(git --git-dir "$GIT_DIR" merge-base "$REF_HEAD" "$UPSTREAM" 2> /dev/null)
[ $DEBUG -eq 1 ] && echo "REV_LOCAL: $REV_LOCAL" [ $DEBUG -eq 1 ] && echo "REV_LOCAL: $REV_LOCAL"
[ $DEBUG -eq 1 ] && echo "REV_REMOTE: $REV_REMOTE" [ $DEBUG -eq 1 ] && echo "REV_REMOTE: $REV_REMOTE"
@ -206,8 +206,10 @@ do
NEEDS_UPSTREAM_BRANCHES=$(printf "$NEEDS_UPSTREAM_BRANCHES" | sort | uniq | tr '\n' ',' | sed "s/^,\(.*\),$/\1/") NEEDS_UPSTREAM_BRANCHES=$(printf "$NEEDS_UPSTREAM_BRANCHES" | sort | uniq | tr '\n' ',' | sed "s/^,\(.*\),$/\1/")
# Find out if there are unstaged, uncommitted or untracked changes # Find out if there are unstaged, uncommitted or untracked changes
UNSTAGED=$(git --work-tree "$(dirname "$GIT_DIR")" --git-dir "$GIT_DIR" diff-index --quiet HEAD -- 2>/dev/null; echo $?) UNSTAGED=$(git --work-tree "$(dirname "$GIT_DIR")" --git-dir "$GIT_DIR" diff-index --quiet HEAD -- 2> /dev/null;
UNCOMMITTED=$(git --work-tree "$(dirname "$GIT_DIR")" --git-dir "$GIT_DIR" diff-files --quiet --ignore-submodules --; echo $?) echo $?)
UNCOMMITTED=$(git --work-tree "$(dirname "$GIT_DIR")" --git-dir "$GIT_DIR" diff-files --quiet --ignore-submodules --;
echo $?)
UNTRACKED=$(git --work-tree "$(dirname "$GIT_DIR")" --git-dir "$GIT_DIR" ls-files --exclude-standard --others) UNTRACKED=$(git --work-tree "$(dirname "$GIT_DIR")" --git-dir "$GIT_DIR" ls-files --exclude-standard --others)
cd "$(dirname "$GIT_DIR")" || exit cd "$(dirname "$GIT_DIR")" || exit
STASHES=$(git stash list | wc -l) STASHES=$(git stash list | wc -l)

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# #
# Delete_User - Automates the 4 steps to remove an account # Delete_User - Automates the 4 steps to remove an account

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
#DIRS="/var/log /home /opt" #DIRS="/var/log /home /opt"

View File

@ -0,0 +1,8 @@
# Shell 脚本大全
> **Shell 脚本大全** 精心收集、整理了 Linux 环境下的常见 Shell 脚本操作片段。
>
> 当您面临以下问题时,**Shell 脚本大全** 也许可以给你一些借鉴:
>
> - 你想要执行某个操作,却不知 Shell 命令如何写
> - 你想要快速掌握 Shell 基本用法

View File

@ -1,3 +0,0 @@
# Shell 示例源码
> 本目录的代码是和 『[一篇文章让你彻底掌握 shell 语言](https://github.com/dunwu/linux-tutorial/blob/master/docs/linux/scripts/shell.md)』 相配套的示例代码。

View File

@ -1,55 +0,0 @@
#!/usr/bin/env bash
# 创建数组
nums=( [ 2 ] = 2 [ 0 ] = 0 [ 1 ] = 1 )
colors=( red yellow "dark blue" )
# 访问数组的单个元素
echo ${nums[1]}
# Output: 1
# 访问数组的所有元素
echo ${colors[*]}
# Output: red yellow dark blue
echo ${colors[@]}
# Output: red yellow dark blue
printf "+ %s\n" ${colors[*]}
# Output:
# + red
# + yellow
# + dark
# + blue
printf "+ %s\n" "${colors[*]}"
# Output:
# + red yellow dark blue
printf "+ %s\n" "${colors[@]}"
# Output:
# + red
# + yellow
# + dark blue
# 访问数组的部分元素
echo ${nums[@]:0:2}
# Output:
# 0 1
# 访问数组长度
echo ${#nums[*]}
# Output:
# 3
# 向数组中添加元素
colors=( white "${colors[@]}" green black )
echo ${colors[@]}
# Output:
# white red yellow dark blue green black
# 从数组中删除元素
unset nums[ 0 ]
echo ${nums[@]}
# Output:
# 1 2

View File

@ -1,42 +0,0 @@
#!/usr/bin/env bash
calc() {
PS3="choose the oper: "
select oper in + - \* / # 生成操作符选择菜单
do
echo -n "enter first num: " && read x # 读取输入参数
echo -n "enter second num: " && read y # 读取输入参数
exec
case ${oper} in
"+")
return $((${x} + ${y}))
;;
"-")
return $((${x} - ${y}))
;;
"*")
return $((${x} * ${y}))
;;
"/")
return $((${x} / ${y}))
;;
*)
echo "${oper} is not support!"
return 0
;;
esac
break
done
}
calc
echo "the result is: $?" # $? 获取 calc 函数返回值
# $ ./function-demo.sh
# 1) +
# 2) -
# 3) *
# 4) /
# choose the oper: 3
# enter first num: 10
# enter second num: 10
# the result is: 100

View File

@ -1,24 +0,0 @@
#!/usr/bin/env bash
x=0
if [[ -n $1 ]]; then
echo "第一个参数为:$1"
x=$1
else
echo "第一个参数为空"
fi
y=0
if [[ -n $2 ]]; then
echo "第二个参数为:$2"
y=$2
else
echo "第二个参数为空"
fi
paramsFunction() {
echo "函数第一个入参:$1"
echo "函数第二个入参:$2"
}
paramsFunction ${x} ${y}

View File

@ -1,3 +0,0 @@
#!/bin/bash
echo "Hello, world!"

View File

@ -1,59 +0,0 @@
#!/usr/bin/env bash
x=10
if [[ -n $1 ]]; then
x=$1
fi
y=20
if [[ -n $2 ]]; then
y=$2
fi
echo "x=${x}, y=${y}"
if [[ ${x} -eq ${y} ]]; then
echo "${x} -eq ${y} : x 等于 y"
else
echo "${x} -eq ${y}: x 不等于 y"
fi
if [[ ${x} -ne ${y} ]]; then
echo "${x} -ne ${y}: x 不等于 y"
else
echo "${x} -ne ${y}: x 等于 y"
fi
if [[ ${x} -gt ${y} ]]; then
echo "${x} -gt ${y}: x 大于 y"
else
echo "${x} -gt ${y}: x 不大于 y"
fi
if [[ ${x} -lt ${y} ]]; then
echo "${x} -lt ${y}: x 小于 y"
else
echo "${x} -lt ${y}: x 不小于 y"
fi
if [[ ${x} -ge ${y} ]]; then
echo "${x} -ge ${y}: x 大于或等于 y"
else
echo "${x} -ge ${y}: x 小于 y"
fi
if [[ ${x} -le ${y} ]]; then
echo "${x} -le ${y}: x 小于或等于 y"
else
echo "${x} -le ${y}: x 大于 y"
fi
# Execute: ./operator-demo2.sh
# Output:
# x=10, y=20
# 10 -eq 20: x 不等于 y
# 10 -ne 20: x 不等于 y
# 10 -gt 20: x 不大于 y
# 10 -lt 20: x 小于 y
# 10 -ge 20: x 小于 y
# 10 -le 20: x 小于或等于 y

View File

@ -1,45 +0,0 @@
#!/usr/bin/env bash
x=10
if [[ -n $1 ]]; then
x=$1
fi
y=20
if [[ -n $2 ]]; then
y=$2
fi
echo "x=${x}, y=${y}"
if [[ ${x} != ${y} ]]; then
echo "${x} != ${y} : x 不等于 y"
else
echo "${x} != ${y}: x 等于 y"
fi
if [[ ${x} -lt 100 && ${y} -gt 15 ]]; then
echo "${x} 小于 100 且 ${y} 大于 15 : 返回 true"
else
echo "${x} 小于 100 且 ${y} 大于 15 : 返回 false"
fi
if [[ ${x} -lt 100 || ${y} -gt 100 ]]; then
echo "${x} 小于 100 或 ${y} 大于 100 : 返回 true"
else
echo "${x} 小于 100 或 ${y} 大于 100 : 返回 false"
fi
if [[ ${x} -lt 5 || ${y} -gt 100 ]]; then
echo "${x} 小于 5 或 ${y} 大于 100 : 返回 true"
else
echo "${x} 小于 5 或 ${y} 大于 100 : 返回 false"
fi
# Execute: ./operator-demo3.sh
# Output:
# x=10, y=20
# 10 != 20 : x 不等于 y
# 10 小于 100 且 20 大于 15 : 返回 true
# 10 小于 100 或 20 大于 100 : 返回 true
# 10 小于 5 或 20 大于 100 : 返回 false

View File

@ -1,49 +0,0 @@
#!/usr/bin/env bash
file="/etc/hosts"
if [[ -r ${file} ]]; then
echo "${file} 文件可读"
else
echo "${file} 文件不可读"
fi
if [[ -w ${file} ]]; then
echo "${file} 文件可写"
else
echo "${file} 文件不可写"
fi
if [[ -x ${file} ]]; then
echo "${file} 文件可执行"
else
echo "${file} 文件不可执行"
fi
if [[ -f ${file} ]]; then
echo "${file} 文件为普通文件"
else
echo "${file} 文件为特殊文件"
fi
if [[ -d ${file} ]]; then
echo "${file} 文件是个目录"
else
echo "${file} 文件不是个目录"
fi
if [[ -s ${file} ]]; then
echo "${file} 文件不为空"
else
echo "${file} 文件为空"
fi
if [[ -e ${file} ]]; then
echo "${file} 文件存在"
else
echo "${file} 文件不存在"
fi
# Execute: ./operator-demo6.sh
# Output:(根据文件的实际情况,输出结果可能不同)
# /etc/hosts 文件可读
# /etc/hosts 文件可写
# /etc/hosts 文件不可执行
# /etc/hosts 文件为普通文件
# /etc/hosts 文件不是个目录
# /etc/hosts 文件不为空
# /etc/hosts 文件存在

View File

@ -1,12 +0,0 @@
#!/usr/bin/env bash
# 查找 10 以内第一个能整除 2 和 3 的正整数
i=1
while [[ ${i} -lt 10 ]]; do
if [[ $((i % 3)) -eq 0 ]] && [[ $((i % 2)) -eq 0 ]]; then
echo ${i}
break;
fi
i=`expr ${i} + 1`
done
# Output: 6

View File

@ -1,41 +0,0 @@
#!/usr/bin/env bash
echo "input param: " $1 $2 $3
x=0
if [[ -n $1 ]]; then
x=$1
fi
y=0
if [[ -n $2 ]]; then
y=$2
fi
oper=""
if [[ -n $3 ]]; then
oper=$3
fi
exec
case ${oper} in
"+")
val=`expr ${x} + ${y}`
echo "${x} + ${y} = ${val}"
;;
"-")
val=`expr ${x} - ${y}`
echo "${x} - ${y} = ${val}"
;;
"*")
val=`expr ${x} \* ${y}`
echo "${x} * ${y} = ${val}"
;;
"/")
val=`expr ${x} / ${y}`
echo "${x} / ${y} = ${val}"
;;
*)
echo "Unknown oper!"
;;
esac

View File

@ -1,15 +0,0 @@
#!/usr/bin/env bash
# 打印10以内的奇数
for (( i = 0; i < 10; i ++ )); do
if [[ $((i % 2)) -eq 0 ]]; then
continue;
fi
echo ${i}
done
# Output:
# 1
# 3
# 5
# 7
# 9

View File

@ -1,39 +0,0 @@
#!/usr/bin/env bash
################### for 语句 ###################
echo "print 0 to 9"
for (( j = 0; j < 10; j ++ )); do
echo ${j}
done
# Output:
# print 0 to 9
# 0
# 1
# 2
# 3
# 4
# 5
# 6
# 7
# 8
# 9
################### for in 语句 ###################
echo "print 1 to 5"
for i in {1..5}; do
echo ${i};
done
# Output:
# print 1 to 5
# 1
# 2
# 3
# 4
# 5
################### for in 语句遍历文件 ###################
DIR=/home/zp
for FILE in ${DIR}/*.sh; do
mv "$FILE" "${DIR}/scripts"
done
# 将 /home/zp 目录下所有 sh 文件拷贝到 /home/zp/scripts

View File

@ -1,35 +0,0 @@
#!/usr/bin/env bash
################### if 语句 ###################
# 写成一行
if [[ 1 -eq 1 ]]; then
echo "1 -eq 1 result is: true";
fi
# Output: 1 -eq 1 result is: true
# 写成多行
if [[ "abc" -eq "abc" ]]
then
echo ""abc" -eq "abc" result is: true"
fi
# Output: abc -eq abc result is: true
################### if else 语句 ###################
if [[ 2 -ne 1 ]]; then
echo "true"
else
echo "false"
fi
# Output: true
################### if elif else 语句 ###################
x=10
y=20
if [[ ${x} > ${y} ]]; then
echo "${x} > ${y}"
elif [[ ${x} < ${y} ]]; then
echo "${x} < ${y}"
else
echo "${x} = ${y}"
fi
# Output: 10 < 20

View File

@ -1,13 +0,0 @@
#!/usr/bin/env bash
x=0
until [[ ${x} -ge 5 ]]; do
echo ${x}
x=`expr ${x} + 1`
done
# Output:
# 0
# 1
# 2
# 3
# 4

View File

@ -1,20 +0,0 @@
#!/usr/bin/env bash
### 0到9之间每个数的平方
x=0
### x小于10
while [[ ${x} -lt 10 ]]; do
echo $((x * x))
x=$((x + 1))
done
# Output:
# 0
# 1
# 4
# 9
# 16
# 25
# 36
# 49
# 64
# 81

View File

@ -1,55 +0,0 @@
#!/usr/bin/env bash
################### 单引号和双引号 ###################
################### 拼接字符串 ###################
# 使用单引号拼接
name1='white'
str1='hello, '${name1}''
str2='hello, ${name1}'
echo ${str1}_${str2}
# Output:
# hello, white_hello, ${name1}
# 使用双引号拼接
name2="black"
str3="hello, "${name2}""
str4="hello, ${name2}"
echo ${str3}_${str4}
# Output:
# hello, black_hello, black
################### 获取字符串长度 ###################
text="12345"
echo "${text} length is: ${#text}"
# Output:
# 12345 length is: 5
################### 获取字符串长度 ###################
text="12345"
echo ${text:2:2}
# Output:
# 34
################### 查找子字符串 ###################
text="hello"
echo `expr index "${text}" ll`
# Output:
# 3
################### 截取关键字左边内容 ###################
full_branch="feature/1.0.0"
branch=`echo ${full_branch#feature/}`
echo "branch is ${branch}"
################### 截取关键字右边内容 ###################
full_version="0.0.1-SNAPSHOT"
version=`echo ${full_version%-SNAPSHOT}`
echo "version is ${version}"
################### 判断字符串中是否包含子字符串 ###################
result=$(echo "${str}" | grep "feature/")
if [[ "$result" != "" ]]; then
echo "feature/ 是 ${str} 的子字符串"
else
echo "feature/ 不是 ${str} 的子字符串"
fi

View File

@ -1,22 +0,0 @@
#!/usr/bin/env bash
################### 声明变量 ###################
name="world"
echo "hello ${name}"
# Output: hello world
################### 只读变量 ###################
rword="hello"
echo ${rword}
# Output: hello
readonly rword
# rword="bye" # 如果放开注释,执行时会报错
################### 删除变量 ###################
dword="hello" # 声明变量
echo ${dword} # 输出变量值
# Output: hello
unset dword # 删除变量
echo ${dword}
# Output: (空)

View File

@ -0,0 +1,22 @@
#!/usr/bin/env bash
# send data to the the table in the MYSQL database
MYSQL=`which mysql`
if [ $# -ne 2 ]
then
echo "Usage:mtest2 emplid lastname firstname salary"
else
#脚本变量一定要用双引号,字符串变量使用单引号
statement=" insert into em_admin values(NULL, '$1', $2)"
$MYSQL emwjs -u test << EOF
$statement
EOF
if [ $? -eq 0 ]
then
echo Data successfully added
else
echo Problem adding data
fi
fi

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
#redirecting SQL output to a variable #redirecting SQL output to a variable

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
#连接数据库 #连接数据库
mysql=`which mysql` mysql=`which mysql`

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
#退出状态码最大为255超过则进行模运算 #退出状态码最大为255超过则进行模运算
#testing the exit status #testing the exit status

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
#An example of using the expr command #An example of using the expr command

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
var1=10.45 var1=10.45
var2=43.67 var2=43.67

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
var1=10 var1=10
var2=50 var2=50

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
#using the backtick character 会把反引号里面当作一条命令来执行 #using the backtick character 会把反引号里面当作一条命令来执行

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
var1=100 var1=100
var2=45 var2=45

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
#This script displays the date and who's logged on #This script displays the date and who's logged on

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
#display user information from system #display user information from system

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
#copy the /usr/bin directory listing to a log file #copy the /usr/bin directory listing to a log file

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# testing the at command # testing the at command

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# testing signal trapping # testing signal trapping

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# trapping the script exit # trapping the script exit

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# removeing a set trap # removeing a set trap

View File

@ -48,7 +48,6 @@ else
echo "${x} -le ${y}: x 大于 y" echo "${x} -le ${y}: x 大于 y"
fi fi
# Execute: ./operator-demo2.sh
# Output: # Output:
# x=10, y=20 # x=10, y=20
# 10 -eq 20: x 不等于 y # 10 -eq 20: x 不等于 y

View File

@ -1,3 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
x="abc" x="abc"
@ -42,7 +43,6 @@ else
echo "${x} : 字符串为空" echo "${x} : 字符串为空"
fi fi
# Execute: ./operator-demo5.sh
# Output: # Output:
# x=abc, y=xyz # x=abc, y=xyz
# abc = xyz: x 不等于 y # abc = xyz: x 不等于 y

View File

@ -36,7 +36,6 @@ else
echo "${x} 小于 5 或 ${y} 大于 100 : 返回 false" echo "${x} 小于 5 或 ${y} 大于 100 : 返回 false"
fi fi
# Execute: ./operator-demo3.sh
# Output: # Output:
# x=10, y=20 # x=10, y=20
# 10 != 20 : x 不等于 y # 10 != 20 : x 不等于 y

View File

@ -38,7 +38,6 @@ else
echo "${file} 文件不存在" echo "${file} 文件不存在"
fi fi
# Execute: ./operator-demo6.sh
# Output:(根据文件的实际情况,输出结果可能不同) # Output:(根据文件的实际情况,输出结果可能不同)
# /etc/hosts 文件可读 # /etc/hosts 文件可读
# /etc/hosts 文件可写 # /etc/hosts 文件可写

View File

@ -34,7 +34,7 @@ if [[ ${x} != ${y} ]]; then
echo "${x} != ${y}" echo "${x} != ${y}"
fi fi
# Execute: ./operator-demo.sh # Execute: ./算术运算符.sh
# Output: # Output:
# x=10, y=20 # x=10, y=20
# 10 + 20 = 30 # 10 + 20 = 30
@ -44,7 +44,7 @@ fi
# 20 % 10 = 0 # 20 % 10 = 0
# 10 != 20 # 10 != 20
# Execute: ./operator-demo.sh 10 30 # Execute: ./算术运算符.sh 10 30
# Output: # Output:
# x=10, y=30 # x=10, y=30
# 10 + 30 = 40 # 10 + 30 = 40

View File

@ -26,7 +26,6 @@ else
echo "${x} -lt 100 || ${y} -gt 100 返回 false" echo "${x} -lt 100 || ${y} -gt 100 返回 false"
fi fi
# Execute: ./operator-demo4.sh
# Output: # Output:
# x=10, y=20 # x=10, y=20
# 10 -lt 100 && 20 -gt 100 返回 false # 10 -lt 100 && 20 -gt 100 返回 false

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
BEGIN { BEGIN {
print "The latest list of users and shells" print "The latest list of users and shells"

View File

@ -5,8 +5,8 @@ function myprint()
printf "%-16s - %s", $1, $4 printf "%-16s - %s", $1, $4
} }
function myrand(limit) function myrand ( limit )
{ {
return int(limit * rand()) return int ( limit * rand ( ) )
} }

View File

@ -0,0 +1,8 @@
#!/bin/bash
BEGIN{ FS="\n";
RS=""}
{
myprint()
}

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
#使用内建变量 #使用内建变量

Some files were not shown because too many files have changed in this diff Show More