mirror of
https://github.com/dunwu/linux-tutorial.git
synced 2024-04-15 19:55:24 +08:00
format codes
This commit is contained in:
parent
d336b79af1
commit
0c58f678fe
@ -1,7 +1,7 @@
|
||||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# http://editorconfig.org
|
||||
# 所有文件换行使用 Unix like 风格(LF),bat 文件使用 win 风格(CRLF)
|
||||
# 所有文件换行以 Unix like 风格(LF),win 格式特定的除外(bat)
|
||||
# 缩进 java 4 个空格,其他所有文件 2 个空格
|
||||
|
||||
root = true
|
||||
@ -11,9 +11,8 @@ root = true
|
||||
end_of_line = lf
|
||||
|
||||
# Change these settings to your own preference
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
max_line_length = 120
|
||||
indent_size = 2
|
||||
|
||||
# We recommend you to keep these unchanged
|
||||
charset = utf-8
|
||||
@ -23,9 +22,8 @@ insert_final_newline = true
|
||||
[*.bat]
|
||||
end_of_line = crlf
|
||||
|
||||
[*.java]
|
||||
[*.{java, sh}]
|
||||
indent_size = 4
|
||||
|
||||
[*.md]
|
||||
max_line_length = 0
|
||||
trim_trailing_whitespace = false
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# 打印UI页头信息
|
||||
function printHeadInfo() {
|
||||
cat << EOF
|
||||
cat << EOF
|
||||
***********************************************************************************
|
||||
* 欢迎使用项目引导式发布脚本。
|
||||
* 输入任意键进入脚本操作。
|
||||
@ -12,7 +12,7 @@ EOF
|
||||
|
||||
# 打印UI页尾信息
|
||||
function printFootInfo() {
|
||||
cat << EOF
|
||||
cat << EOF
|
||||
|
||||
|
||||
***********************************************************************************
|
||||
@ -34,7 +34,7 @@ function checkFileExist() {
|
||||
|
||||
# 检查文件夹是否存在,不存在则创建
|
||||
function createFolderIfNotExist() {
|
||||
if [ ! -d "$1" ];then
|
||||
if [ ! -d "$1" ]; then
|
||||
mkdir -p "$1"
|
||||
fi
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ function checkInput() {
|
||||
|
||||
# 检查文件夹是否存在,不存在则创建
|
||||
function createFolderIfNotExist() {
|
||||
if [ ! -d "$1" ];then
|
||||
if [ ! -d "$1" ]; then
|
||||
mkdir -p "$1"
|
||||
fi
|
||||
}
|
||||
@ -38,10 +38,10 @@ function checkStarted() {
|
||||
|
||||
function main() {
|
||||
case "${oper}" in
|
||||
start )
|
||||
start)
|
||||
echo -n "starting server: "
|
||||
# 检查服务是否已经启动
|
||||
if checkStarted ;then
|
||||
if checkStarted; then
|
||||
echo "ERROR: server already started!"
|
||||
echo "PID: ${pids}"
|
||||
exit 1
|
||||
@ -56,22 +56,22 @@ function main() {
|
||||
# echo -e "执行参数:\n${args}"
|
||||
echo -e "\nthe server is started..."
|
||||
;;
|
||||
stop )
|
||||
stop)
|
||||
echo -n "stopping server: "
|
||||
#dubbo提供优雅停机, 不能使用kill -9
|
||||
if checkStarted ;then
|
||||
if checkStarted; then
|
||||
kill ${pids}
|
||||
echo -e "\nthe server is stopped..."
|
||||
else
|
||||
echo -e "\nno server to be stopped..."
|
||||
fi
|
||||
;;
|
||||
restart )
|
||||
restart)
|
||||
$0 ${app} stop "${javaArgs}" "${classpathArgs}" "${bootstrapClass}"
|
||||
sleep 5
|
||||
$0 ${app} start "${javaArgs}" "${classpathArgs}" "${bootstrapClass}"
|
||||
;;
|
||||
* )
|
||||
*)
|
||||
echo "Invalid oper: ${oper}."
|
||||
exit 1
|
||||
esac
|
||||
|
@ -27,7 +27,7 @@ checkFileExist() {
|
||||
|
||||
# 检查文件夹是否存在,不存在则创建
|
||||
createFolderIfNotExist() {
|
||||
if [ ! -d "$1" ];then
|
||||
if [ ! -d "$1" ]; then
|
||||
mkdir -p "$1"
|
||||
fi
|
||||
}
|
||||
@ -50,7 +50,8 @@ export LANG="zh_CN.UTF-8"
|
||||
|
||||
# 设置全局常量
|
||||
LOG_DIR=/home/zp/log/
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")";
|
||||
pwd)
|
||||
SOURCE_DIR=/home/zp/source/
|
||||
APP_NAME=XXX
|
||||
RESOURCES_DIR=/home/zp/source/${APP_NAME}/src/main/resources
|
||||
|
@ -26,7 +26,7 @@ function checkFileExist() {
|
||||
}
|
||||
|
||||
# 封装启动参数,调用启动脚本
|
||||
function main(){
|
||||
function main() {
|
||||
APP_NAME=ck-lion
|
||||
|
||||
# JVM 参数
|
||||
@ -59,7 +59,8 @@ function main(){
|
||||
export LANG="zh_CN.UTF-8"
|
||||
|
||||
# 设置全局常量
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")";
|
||||
pwd)
|
||||
SOURCE_DIR=/home/zp/source/
|
||||
APP_NAME=XXX
|
||||
SERVER_ROOT=/home/zp/source/${APP_NAME}/target/
|
||||
|
@ -59,7 +59,8 @@ export LANG="zh_CN.UTF-8"
|
||||
APP=blog
|
||||
LOG_DIR=/home/zp/log
|
||||
SOURCE_DIR=/home/zp/source
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")";
|
||||
pwd)
|
||||
|
||||
# 装载函数库
|
||||
. ${SCRIPT_DIR}/helper.sh
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
# 选择应用
|
||||
function chooseAppName() {
|
||||
cat << EOF
|
||||
cat << EOF
|
||||
请选择应用名(数字或关键字均可)。
|
||||
可选值如下:
|
||||
[0] all (所有应用)
|
||||
@ -15,28 +15,28 @@ cat << EOF
|
||||
[2] APP2
|
||||
EOF
|
||||
|
||||
while read app
|
||||
do
|
||||
while read app
|
||||
do
|
||||
case ${app} in
|
||||
0 )
|
||||
0)
|
||||
app=all
|
||||
break ;;
|
||||
1 )
|
||||
1)
|
||||
app=js-app
|
||||
break ;;
|
||||
2 )
|
||||
2)
|
||||
app=APP2
|
||||
break ;;
|
||||
all | js-app | APP2 )
|
||||
all | js-app | APP2)
|
||||
break ;;
|
||||
* ) echo "无法识别 ${app}" ;;
|
||||
*) echo "无法识别 ${app}" ;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# 选择操作
|
||||
function chooseOper() {
|
||||
cat << EOF
|
||||
cat << EOF
|
||||
请选择想要执行的操作(数字或关键字均可)。
|
||||
可选值如下:
|
||||
[1] start
|
||||
@ -44,44 +44,44 @@ cat << EOF
|
||||
[3] stop
|
||||
EOF
|
||||
|
||||
while read oper
|
||||
do
|
||||
while read oper
|
||||
do
|
||||
case ${oper} in
|
||||
1 )
|
||||
1)
|
||||
oper=start
|
||||
break ;;
|
||||
2 )
|
||||
2)
|
||||
oper=restart
|
||||
break ;;
|
||||
3 )
|
||||
3)
|
||||
oper=stop
|
||||
break ;;
|
||||
start | restart | stop )
|
||||
start | restart | stop)
|
||||
break ;;
|
||||
* ) echo "无法识别 ${oper}" ;;
|
||||
*) echo "无法识别 ${oper}" ;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# 选择代码分支
|
||||
function chooseBranch() {
|
||||
cat << EOF
|
||||
cat << EOF
|
||||
请输入 git 分支。
|
||||
如:develop、master、feature/xxx
|
||||
EOF
|
||||
|
||||
read branch
|
||||
if [[ "${branch}" =~ ^(feature/)([^ \f\n\r\t\v]+) ]] || [ "${branch}" == "develop" ] || [ "${branch}" == "master" ]; then
|
||||
read branch
|
||||
if [[ "${branch}" =~ ^ ( feature/ ) ( [^ \f\n\r\t\v]+ ) ]] || [ "${branch}" == "develop" ] || [ "${branch}" == "master" ]; then
|
||||
echo "输入了 ${branch}"
|
||||
else
|
||||
else
|
||||
echo "无法识别 ${branch}"
|
||||
chooseBranch
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# 选择运行环境
|
||||
function chooseProfile() {
|
||||
cat << EOF
|
||||
cat << EOF
|
||||
请选择运行环境(数字或关键字均可)。
|
||||
可选值:
|
||||
[1] develop (开发环境)
|
||||
@ -90,32 +90,32 @@ cat << EOF
|
||||
[4] product (生产环境)
|
||||
EOF
|
||||
|
||||
while read profile
|
||||
do
|
||||
while read profile
|
||||
do
|
||||
case ${profile} in
|
||||
1 )
|
||||
1)
|
||||
profile=develop
|
||||
break ;;
|
||||
2 )
|
||||
2)
|
||||
profile=test
|
||||
break ;;
|
||||
3 )
|
||||
3)
|
||||
profile=preview
|
||||
break ;;
|
||||
4 )
|
||||
4)
|
||||
profile=product
|
||||
break ;;
|
||||
develop | test | preview | product )
|
||||
develop | test | preview | product)
|
||||
break ;;
|
||||
* ) echo "无法识别 ${profile}" ;;
|
||||
*) echo "无法识别 ${profile}" ;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# 确认选择
|
||||
function confirmChoice() {
|
||||
|
||||
cat << EOF
|
||||
cat << EOF
|
||||
===================================================
|
||||
请确认您的选择:Y/N
|
||||
app: ${app}
|
||||
@ -128,13 +128,13 @@ EOF
|
||||
while read confirm
|
||||
do
|
||||
case ${confirm} in
|
||||
y | Y )
|
||||
y | Y)
|
||||
echo -e "\n\n>>>>>>>>>>>>>> 开始发布应用"
|
||||
break ;;
|
||||
n | N )
|
||||
n | N)
|
||||
echo -e "重新输入发布参数\n"
|
||||
inputParams ;;
|
||||
* )
|
||||
*)
|
||||
echo "无法识别 ${confirm}" ;;
|
||||
esac
|
||||
done
|
||||
@ -171,20 +171,20 @@ function releaseApp() {
|
||||
# 脚本主方法
|
||||
function main() {
|
||||
|
||||
printHeadInfo
|
||||
while read sign
|
||||
do
|
||||
printHeadInfo
|
||||
while read sign
|
||||
do
|
||||
case ${sign} in
|
||||
exit)
|
||||
echo "主动退出脚本"
|
||||
exit 0 ;;
|
||||
* )
|
||||
*)
|
||||
releaseApp ;;
|
||||
esac
|
||||
|
||||
# 装载函数库
|
||||
printFootInfo
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
@ -192,7 +192,8 @@ done
|
||||
export LANG="zh_CN.UTF-8"
|
||||
|
||||
# 设置全局常量
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")";
|
||||
pwd)
|
||||
SOURCE_DIR=/home/zp/source/
|
||||
|
||||
# 装载函数库
|
||||
|
@ -20,7 +20,7 @@ checkInput() {
|
||||
|
||||
# 检查文件夹是否存在,不存在则创建
|
||||
function createFolderIfNotExist() {
|
||||
if [ ! -d "$1" ];then
|
||||
if [ ! -d "$1" ]; then
|
||||
mkdir -p "$1"
|
||||
fi
|
||||
}
|
||||
|
@ -29,8 +29,10 @@ printf "${RESET}"
|
||||
|
||||
path=/home/scripts/linux-tutorial
|
||||
printf "\n${GREEN}>>>>>>>> Download linux-tutorial to ${path} begin.${RESET}\n"
|
||||
command -v yum >/dev/null 2>&1 || { printf "${RED}Not detected yum.${RESET}"; exit 1; }
|
||||
command -v git >/dev/null 2>&1 || { printf "${YELLOW}Not detected git. Install git.${RESET}\n"; yum -y install git; }
|
||||
command -v yum > /dev/null 2>&1 || { printf "${RED}Not detected yum.${RESET}";
|
||||
exit 1; }
|
||||
command -v git > /dev/null 2>&1 || { printf "${YELLOW}Not detected git. Install git.${RESET}\n";
|
||||
yum -y install git; }
|
||||
|
||||
if [[ -d ${path} ]]; then
|
||||
cd ${path}
|
||||
|
@ -14,8 +14,8 @@ RESET="$(tput sgr0)"
|
||||
|
||||
# 打印头部信息
|
||||
printHeadInfo() {
|
||||
printf "${BLUE}"
|
||||
cat << EOF
|
||||
printf "${BLUE}"
|
||||
cat << EOF
|
||||
|
||||
***********************************************************************************
|
||||
* 欢迎使用 Linux CentOS 环境运维脚本
|
||||
@ -23,25 +23,25 @@ cat << EOF
|
||||
***********************************************************************************
|
||||
|
||||
EOF
|
||||
printf "${RESET}"
|
||||
printf "${RESET}"
|
||||
}
|
||||
|
||||
# 打印尾部信息
|
||||
printFootInfo() {
|
||||
printf "${BLUE}"
|
||||
cat << EOF
|
||||
printf "${BLUE}"
|
||||
cat << EOF
|
||||
|
||||
***********************************************************************************
|
||||
* 脚本执行结束,感谢使用!
|
||||
***********************************************************************************
|
||||
|
||||
EOF
|
||||
printf "${RESET}"
|
||||
printf "${RESET}"
|
||||
}
|
||||
|
||||
# 检查操作系统环境
|
||||
checkOsVersion(){
|
||||
if(($1 == 1)); then
|
||||
checkOsVersion() {
|
||||
if (($1 == 1)); then
|
||||
echo -e "检查操作系统环境是否兼容本套脚本"
|
||||
|
||||
platform=`uname -i`
|
||||
@ -60,12 +60,12 @@ checkOsVersion(){
|
||||
fi
|
||||
}
|
||||
|
||||
menus=("配置系统" "安装软件" "退出")
|
||||
menus=( "配置系统" "安装软件" "退出" )
|
||||
main() {
|
||||
PS3="请输入命令编号:"
|
||||
select item in ${menus[@]}
|
||||
do
|
||||
case ${item} in
|
||||
PS3="请输入命令编号:"
|
||||
select item in ${menus[@]}
|
||||
do
|
||||
case ${item} in
|
||||
"配置系统")
|
||||
./dunwu-sys.sh
|
||||
main ;;
|
||||
@ -77,13 +77,14 @@ case ${item} in
|
||||
*)
|
||||
printf "输入项不支持!\n"
|
||||
main ;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
esac
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
path=$(cd "$(dirname "$0")"; pwd)
|
||||
path=$(cd "$(dirname "$0")";
|
||||
pwd)
|
||||
printHeadInfo
|
||||
checkOsVersion 0
|
||||
main
|
||||
|
@ -24,8 +24,8 @@ EOF
|
||||
|
||||
# print menu
|
||||
printf "${PURPLE}"
|
||||
menus=(docker fastdfs gitlab jdk8 jenkins kafka maven mongodb mysql nacos nexus nginx nodejs redis rocketmq tomcat8
|
||||
zookeeper zsh exit)
|
||||
menus=( docker fastdfs gitlab jdk8 jenkins kafka maven mongodb mysql nacos nexus nginx nodejs redis rocketmq tomcat8
|
||||
zookeeper zsh exit )
|
||||
for i in "${!menus[@]}"; do
|
||||
index=`expr ${i} + 1`
|
||||
val=`expr ${index} % 2`
|
||||
@ -38,8 +38,8 @@ printf "\n${RESET}请输入需要安装的软件编号:\n"
|
||||
|
||||
# exec shell to install soft
|
||||
doInstall() {
|
||||
read -t 30 index
|
||||
if [[ -n ${index} ]]; then
|
||||
read -t 30 index
|
||||
if [[ -n ${index} ]]; then
|
||||
no=`expr ${index} - 1`
|
||||
len=${#menus[*]}
|
||||
if [[ ${index} -gt ${len} ]]; then
|
||||
@ -52,9 +52,10 @@ if [[ -n ${index} ]]; then
|
||||
fi
|
||||
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/${key}-install.sh | bash
|
||||
doInstall
|
||||
else
|
||||
else
|
||||
echo "输入项不支持!"
|
||||
exit -1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
doInstall
|
||||
|
@ -9,12 +9,12 @@ cat << EOF
|
||||
|
||||
EOF
|
||||
|
||||
menus=("替换yum镜像" "安装基本的命令工具" "安装常用libs" "系统配置" "全部执行" "退出")
|
||||
menus=( "替换yum镜像" "安装基本的命令工具" "安装常用libs" "系统配置" "全部执行" "退出" )
|
||||
main() {
|
||||
PS3="请输入命令编号:"
|
||||
select item in ${menus[@]}
|
||||
do
|
||||
case ${item} in
|
||||
PS3="请输入命令编号:"
|
||||
select item in ${menus[@]}
|
||||
do
|
||||
case ${item} in
|
||||
"替换yum镜像")
|
||||
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/change-yum-repo.sh | bash
|
||||
main ;;
|
||||
@ -38,9 +38,9 @@ case ${item} in
|
||||
*)
|
||||
printf "输入项不支持!\n"
|
||||
main ;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
esac
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
|
@ -29,10 +29,10 @@ checkFileExist() {
|
||||
startup() {
|
||||
if [ "${app}" == "elasticsearch" ]; then
|
||||
checkFileExist ${ELASTICSEARCH_BIN_PATH}/elasticsearch
|
||||
nohup sh ${ELASTICSEARCH_BIN_PATH}/elasticsearch >>${ELASTICSEARCH_BIN_PATH}/nohup.out 2>&1 &
|
||||
nohup sh ${ELASTICSEARCH_BIN_PATH}/elasticsearch >> ${ELASTICSEARCH_BIN_PATH}/nohup.out 2>&1 &
|
||||
elif [ "${app}" == "logstash" ]; then
|
||||
checkFileExist ${LOGSTASH_BIN_PATH}/logstash
|
||||
nohup sh ${LOGSTASH_BIN_PATH}/logstash -f ${LOGSTASH_BIN_PATH}/logstash.conf >>${LOGSTASH_BIN_PATH}/nohup.out 2>&1 &
|
||||
nohup sh ${LOGSTASH_BIN_PATH}/logstash -f ${LOGSTASH_BIN_PATH}/logstash.conf >> ${LOGSTASH_BIN_PATH}/nohup.out 2>&1 &
|
||||
elif [ "${app}" == "kibana" ]; then
|
||||
checkFileExist ${KIBANA_BIN_PATH}/kibana
|
||||
nohup sh ${KIBANA_BIN_PATH}/kibana >> ${KIBANA_BIN_PATH}/nohup.out 2>&1 &
|
||||
@ -68,6 +68,6 @@ case ${oper} in
|
||||
echo "终止 ${app}"
|
||||
shutdown
|
||||
;;
|
||||
* ) echo "${oper} is invalid oper";;
|
||||
*) echo "${oper} is invalid oper" ;;
|
||||
esac
|
||||
|
||||
|
@ -101,6 +101,7 @@ setPrivilegeForUser() {
|
||||
chown -R elk.elk ${ELASTIC_SOFTWARE_PATH}
|
||||
chown -R elk.elk /var/log/
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
echo -e "\n>>>>>>>>> install elk"
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# auth:kaliarch
|
||||
# version:v1.0
|
||||
# func:elasticsearch 5.4.1/6.0.1/6.3.1安装
|
||||
@ -12,9 +13,9 @@ env_file=/etc/profile.d/elasticsearch.sh
|
||||
install_log_path=/var/log/appinstall/
|
||||
install_path=/usr/local/
|
||||
software_config_file=${install_path}elasticsearch/config/elasticsearch.yml
|
||||
sysversion=$(rpm -q centos-release|cut -d- -f3)
|
||||
sysversion=$(rpm -q centos-release | cut -d- -f3)
|
||||
jvm_conf="/usr/local/elasticsearch/config/jvm.options"
|
||||
sys_mem=`free -m|grep Mem:|awk '{print $2}'|awk '{sum+=$1} END {print sum/1024}'|cut -d. -f1`
|
||||
sys_mem=`free -m | grep Mem: | awk '{print $2}' | awk '{sum+=$1} END {print sum/1024}' | cut -d. -f1`
|
||||
hostname=elk-server
|
||||
|
||||
clear
|
||||
@ -29,13 +30,13 @@ echo "3: Install elasticsearch 6.3.1"
|
||||
echo "4: EXIT"
|
||||
# 选择安装软件版本
|
||||
read -p "Please input your choice:" softversion
|
||||
if [ "${softversion}" == "1" ];then
|
||||
if [ "${softversion}" == "1" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/elasticsearch/elasticsearch-5.4.1.tar.gz"
|
||||
elif [ "${softversion}" == "2" ];then
|
||||
elif [ "${softversion}" == "2" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/elasticsearch/elasticsearch-6.0.1.tar.gz"
|
||||
elif [ "${softversion}" == "3" ];then
|
||||
elif [ "${softversion}" == "3" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/elasticsearch/elasticsearch-6.3.1.tar.gz"
|
||||
elif [ "${softversion}" == "4" ];then
|
||||
elif [ "${softversion}" == "4" ]; then
|
||||
echo "you choce channel!"
|
||||
exit 1;
|
||||
else
|
||||
@ -45,7 +46,7 @@ fi
|
||||
|
||||
# 传入内容,格式化内容输出,可以传入多个参数,用空格隔开
|
||||
output_msg() {
|
||||
for msg in $*;do
|
||||
for msg in $*; do
|
||||
action $msg /bin/true
|
||||
done
|
||||
}
|
||||
@ -54,11 +55,11 @@ output_msg() {
|
||||
# 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称
|
||||
check_yum_command() {
|
||||
output_msg "命令检查:$1"
|
||||
hash $1 >/dev/null 2>&1
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0
|
||||
hash $1 > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 " >> ${install_log_path}${install_log_name} && return 0
|
||||
else
|
||||
yum -y install $2 >/dev/null 2>&1
|
||||
yum -y install $2 > /dev/null 2>&1
|
||||
# hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 }
|
||||
fi
|
||||
}
|
||||
@ -66,8 +67,8 @@ check_yum_command() {
|
||||
# 判断目录是否存在,传入目录绝对路径,可以传入多个目录
|
||||
check_dir() {
|
||||
output_msg "目录检查"
|
||||
for dirname in $*;do
|
||||
[ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1
|
||||
for dirname in $*; do
|
||||
[ -d $dirname ] || mkdir -p $dirname > /dev/null 2>&1
|
||||
echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name}
|
||||
done
|
||||
}
|
||||
@ -76,12 +77,12 @@ check_dir() {
|
||||
download_file() {
|
||||
output_msg "下载源码包"
|
||||
mkdir -p $download_path
|
||||
for file in $*;do
|
||||
for file in $*; do
|
||||
wget $file -c -P $download_path &> /dev/null
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name}
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!" >> ${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!" >> ${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -90,13 +91,13 @@ download_file() {
|
||||
# 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录
|
||||
extract_file() {
|
||||
output_msg "解压源码"
|
||||
for file in $*;do
|
||||
if [ "${file##*.}" == "gz" ];then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ];then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
for file in $*; do
|
||||
if [ "${file##*.}" == "gz" ]; then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path" >> ${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ]; then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path" >> ${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!" >> ${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -105,38 +106,38 @@ extract_file() {
|
||||
config_env() {
|
||||
output_msg "环境变量配置"
|
||||
|
||||
echo "export PATH=\$PATH:$1" >${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name}
|
||||
echo "export PATH=\$PATH:$1" > ${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!" >> ${install_log_path}${install_log_name}
|
||||
|
||||
}
|
||||
|
||||
# 配置主机名,第一个为主机名
|
||||
config_hostname() {
|
||||
if [ ${sysversion} -eq 6 ];then
|
||||
if [ ${sysversion} -eq 6 ]; then
|
||||
hostname $1
|
||||
elif [ ${sysversion} -eq 7 ];then
|
||||
elif [ ${sysversion} -eq 7 ]; then
|
||||
hostnamectl set-hostname $1
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` hostname $1 config fail">> ${install_log_path}${install_log_name}
|
||||
fi
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` hostname $1 config fail" >> ${install_log_path}${install_log_name}
|
||||
fi
|
||||
}
|
||||
|
||||
config_limits() {
|
||||
output_msg "配置limits"
|
||||
cat >>/etc/security/limits.conf<<EOF
|
||||
cat >> /etc/security/limits.conf << EOF
|
||||
* soft nofile 65536
|
||||
* hard nofile 65536
|
||||
* soft nproc 65536
|
||||
* hard nproc 65536
|
||||
EOF
|
||||
echo "vm.max_map_count = 655360" >>/etc/sysctl.conf
|
||||
sysctl -p >/dev/null 2>&1
|
||||
echo "vm.max_map_count = 655360" >> /etc/sysctl.conf
|
||||
sysctl -p > /dev/null 2>&1
|
||||
|
||||
}
|
||||
|
||||
# 添加配置文件
|
||||
add_config() {
|
||||
cat > $1 << EOF
|
||||
cat > $1 << EOF
|
||||
cluster.name: my-application
|
||||
node.name: ${hostname}
|
||||
path.data: /usr/local/elasticsearch/data
|
||||
@ -148,46 +149,46 @@ EOF
|
||||
}
|
||||
|
||||
config_user() {
|
||||
useradd $1 >/dev/null 2>&1
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` $1 user add success">> ${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` $1 user add fail">> ${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
chown ${1}.${1} ${install_path}elasticsearch/ -R
|
||||
useradd $1 > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "`date +%F' '%H:%M:%S` $1 user add success" >> ${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` $1 user add fail" >> ${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
chown ${1}.${1} ${install_path}elasticsearch/ -R
|
||||
}
|
||||
|
||||
config_jvm() {
|
||||
if [ ${sys_mem} -eq 0 ];then
|
||||
if [ ${sys_mem} -eq 0 ]; then
|
||||
sed -i "s#`grep "^-Xmx" ${jvm_conf}`#"-Xmx512m"#g" ${jvm_conf}
|
||||
sed -i "s#`grep "^-Xms" ${jvm_conf}`#"-Xms512m"#g" ${jvm_conf}
|
||||
else
|
||||
else
|
||||
sed -i "s#`grep "^-Xmx" ${jvm_conf}`#"-Xmx${sys_mem}g"#g" ${jvm_conf}
|
||||
sed -i "s#`grep "^-Xms" ${jvm_conf}`#"-Xms${sys_mem}g"#g" ${jvm_conf}
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
config_hostname $hostname
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
config_hostname $hostname
|
||||
|
||||
software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'.tar.gz' '{print $1}')
|
||||
for filename in `ls $download_path`;do
|
||||
software_name=$(echo $URL | awk -F'/' '{print $NF}' | awk -F'.tar.gz' '{print $1}')
|
||||
for filename in `ls $download_path`; do
|
||||
extract_file ${download_path}$filename
|
||||
done
|
||||
done
|
||||
|
||||
rm -fr ${download_path}
|
||||
ln -s $install_path$software_name ${install_path}elasticsearch
|
||||
add_config $software_config_file
|
||||
check_dir ${install_path}elasticsearch/{data,logs}
|
||||
config_user elasticsearch
|
||||
config_env ${install_path}elasticsearch/bin
|
||||
config_limits
|
||||
config_jvm
|
||||
echo "请使用一下命令启动服务:'su - elasticsearch -c 'nohup /usr/local/elasticsearch/bin/elasticsearch &'"
|
||||
rm -fr ${download_path}
|
||||
ln -s $install_path$software_name ${install_path}elasticsearch
|
||||
add_config $software_config_file
|
||||
check_dir ${install_path}elasticsearch/{data,logs}
|
||||
config_user elasticsearch
|
||||
config_env ${install_path}elasticsearch/bin
|
||||
config_limits
|
||||
config_jvm
|
||||
echo "请使用一下命令启动服务:'su - elasticsearch -c 'nohup /usr/local/elasticsearch/bin/elasticsearch &'"
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# auth:kaliarch
|
||||
# version:v1.0
|
||||
# func:filebeat 5.6.1/6.1.3/6.3.2 安装
|
||||
@ -26,13 +27,13 @@ echo "3: Install filebeat 6.3.2"
|
||||
echo "4: EXIT"
|
||||
# 选择安装软件版本
|
||||
read -p "Please input your choice:" softversion
|
||||
if [ "${softversion}" == "1" ];then
|
||||
if [ "${softversion}" == "1" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/filebeat/filebeat-5.6.1-linux-x86_64.tar.gz"
|
||||
elif [ "${softversion}" == "2" ];then
|
||||
elif [ "${softversion}" == "2" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/filebeat/filebeat-6.1.3-linux-x86_64.tar.gz"
|
||||
elif [ "${softversion}" == "3" ];then
|
||||
elif [ "${softversion}" == "3" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/filebeat/filebeat-6.3.2-linux-x86_64.tar.gz"
|
||||
elif [ "${softversion}" == "4" ];then
|
||||
elif [ "${softversion}" == "4" ]; then
|
||||
echo "you choce channel!"
|
||||
exit 1;
|
||||
else
|
||||
@ -42,7 +43,7 @@ fi
|
||||
|
||||
# 传入内容,格式化内容输出,可以传入多个参数,用空格隔开
|
||||
output_msg() {
|
||||
for msg in $*;do
|
||||
for msg in $*; do
|
||||
action $msg /bin/true
|
||||
done
|
||||
}
|
||||
@ -51,11 +52,11 @@ output_msg() {
|
||||
# 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称
|
||||
check_yum_command() {
|
||||
output_msg "命令检查:$1"
|
||||
hash $1 >/dev/null 2>&1
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0
|
||||
hash $1 > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 " >> ${install_log_path}${install_log_name} && return 0
|
||||
else
|
||||
yum -y install $2 >/dev/null 2>&1
|
||||
yum -y install $2 > /dev/null 2>&1
|
||||
# hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 }
|
||||
fi
|
||||
}
|
||||
@ -63,8 +64,8 @@ check_yum_command() {
|
||||
# 判断目录是否存在,传入目录绝对路径,可以传入多个目录
|
||||
check_dir() {
|
||||
output_msg "目录检查"
|
||||
for dirname in $*;do
|
||||
[ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1
|
||||
for dirname in $*; do
|
||||
[ -d $dirname ] || mkdir -p $dirname > /dev/null 2>&1
|
||||
echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name}
|
||||
done
|
||||
}
|
||||
@ -73,12 +74,12 @@ check_dir() {
|
||||
download_file() {
|
||||
output_msg "下载源码包"
|
||||
mkdir -p $download_path
|
||||
for file in $*;do
|
||||
for file in $*; do
|
||||
wget $file -c -P $download_path &> /dev/null
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name}
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!" >> ${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!" >> ${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -87,13 +88,13 @@ download_file() {
|
||||
# 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录
|
||||
extract_file() {
|
||||
output_msg "解压源码"
|
||||
for file in $*;do
|
||||
if [ "${file##*.}" == "gz" ];then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ];then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
for file in $*; do
|
||||
if [ "${file##*.}" == "gz" ]; then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path" >> ${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ]; then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path" >> ${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!" >> ${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -101,14 +102,14 @@ extract_file() {
|
||||
# 配置环境变量,第一个参数为添加环境变量的绝对路径
|
||||
config_env() {
|
||||
output_msg "环境变量配置"
|
||||
echo "export PATH=\$PATH:$1" >${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name}
|
||||
echo "export PATH=\$PATH:$1" > ${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!" >> ${install_log_path}${install_log_name}
|
||||
|
||||
}
|
||||
|
||||
# 添加配置文件
|
||||
add_config() {
|
||||
cat> $1 <<EOF
|
||||
cat > $1 << EOF
|
||||
filebeat.prospectors:
|
||||
- input_type: log
|
||||
paths:
|
||||
@ -119,17 +120,17 @@ EOF
|
||||
}
|
||||
|
||||
main() {
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
|
||||
software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'.tar.gz' '{print $1}')
|
||||
for filename in `ls $download_path`;do
|
||||
software_name=$(echo $URL | awk -F'/' '{print $NF}' | awk -F'.tar.gz' '{print $1}')
|
||||
for filename in `ls $download_path`; do
|
||||
extract_file ${download_path}$filename
|
||||
done
|
||||
rm -fr ${download_path}
|
||||
ln -s $install_path$software_name ${install_path}filebeat
|
||||
add_config ${software_config_file}
|
||||
done
|
||||
rm -fr ${download_path}
|
||||
ln -s $install_path$software_name ${install_path}filebeat
|
||||
add_config ${software_config_file}
|
||||
}
|
||||
|
||||
main
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# auth:kaliarch
|
||||
# version:v1.0
|
||||
# func:kibana 6.0.1/6.2.4/6.3.1 安装
|
||||
@ -26,13 +27,13 @@ echo "3: Install kibana 6.3.1"
|
||||
echo "4: EXIT"
|
||||
# 选择安装软件版本
|
||||
read -p "Please input your choice:" softversion
|
||||
if [ "${softversion}" == "1" ];then
|
||||
if [ "${softversion}" == "1" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kibana/kibana-6.0.1-linux-x86_64.tar.gz"
|
||||
elif [ "${softversion}" == "2" ];then
|
||||
elif [ "${softversion}" == "2" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kibana/kibana-6.2.4-linux-x86_64.tar.gz"
|
||||
elif [ "${softversion}" == "3" ];then
|
||||
elif [ "${softversion}" == "3" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kibana/kibana-6.3.1-linux-x86_64.tar.gz"
|
||||
elif [ "${softversion}" == "4" ];then
|
||||
elif [ "${softversion}" == "4" ]; then
|
||||
echo "you choce channel!"
|
||||
exit 1;
|
||||
else
|
||||
@ -42,7 +43,7 @@ fi
|
||||
|
||||
# 传入内容,格式化内容输出,可以传入多个参数,用空格隔开
|
||||
output_msg() {
|
||||
for msg in $*;do
|
||||
for msg in $*; do
|
||||
action $msg /bin/true
|
||||
done
|
||||
}
|
||||
@ -51,11 +52,11 @@ output_msg() {
|
||||
# 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称
|
||||
check_yum_command() {
|
||||
output_msg "命令检查:$1"
|
||||
hash $1 >/dev/null 2>&1
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0
|
||||
hash $1 > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 " >> ${install_log_path}${install_log_name} && return 0
|
||||
else
|
||||
yum -y install $2 >/dev/null 2>&1
|
||||
yum -y install $2 > /dev/null 2>&1
|
||||
# hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 }
|
||||
fi
|
||||
}
|
||||
@ -63,8 +64,8 @@ check_yum_command() {
|
||||
# 判断目录是否存在,传入目录绝对路径,可以传入多个目录
|
||||
check_dir() {
|
||||
output_msg "目录检查"
|
||||
for dirname in $*;do
|
||||
[ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1
|
||||
for dirname in $*; do
|
||||
[ -d $dirname ] || mkdir -p $dirname > /dev/null 2>&1
|
||||
echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name}
|
||||
done
|
||||
}
|
||||
@ -73,12 +74,12 @@ check_dir() {
|
||||
download_file() {
|
||||
output_msg "下载源码包"
|
||||
mkdir -p $download_path
|
||||
for file in $*;do
|
||||
for file in $*; do
|
||||
wget $file -c -P $download_path &> /dev/null
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name}
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!" >> ${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!" >> ${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -87,13 +88,13 @@ download_file() {
|
||||
# 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录
|
||||
extract_file() {
|
||||
output_msg "解压源码"
|
||||
for file in $*;do
|
||||
if [ "${file##*.}" == "gz" ];then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ];then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
for file in $*; do
|
||||
if [ "${file##*.}" == "gz" ]; then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path" >> ${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ]; then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path" >> ${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!" >> ${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -101,14 +102,14 @@ extract_file() {
|
||||
# 配置环境变量,第一个参数为添加环境变量的绝对路径
|
||||
config_env() {
|
||||
output_msg "环境变量配置"
|
||||
echo "export PATH=\$PATH:$1" >${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name}
|
||||
echo "export PATH=\$PATH:$1" > ${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!" >> ${install_log_path}${install_log_name}
|
||||
|
||||
}
|
||||
|
||||
# 添加配置文件
|
||||
add_config() {
|
||||
cat> $1 <<EOF
|
||||
cat > $1 << EOF
|
||||
server.port: 5601
|
||||
server.host: "0.0.0.0"
|
||||
elasticsearch.url: "http://127.0.0.1:9200"
|
||||
@ -116,18 +117,18 @@ EOF
|
||||
}
|
||||
|
||||
main() {
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
|
||||
software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'.tar.gz' '{print $1}')
|
||||
for filename in `ls $download_path`;do
|
||||
software_name=$(echo $URL | awk -F'/' '{print $NF}' | awk -F'.tar.gz' '{print $1}')
|
||||
for filename in `ls $download_path`; do
|
||||
extract_file ${download_path}$filename
|
||||
done
|
||||
rm -fr ${download_path}
|
||||
ln -s ${install_path}$software_name ${install_path}kibana
|
||||
add_config ${software_config_file}
|
||||
config_env ${install_path}kibana/bin
|
||||
done
|
||||
rm -fr ${download_path}
|
||||
ln -s ${install_path}$software_name ${install_path}kibana
|
||||
add_config ${software_config_file}
|
||||
config_env ${install_path}kibana/bin
|
||||
}
|
||||
|
||||
main
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# auth:kaliarch
|
||||
# version:v1.0
|
||||
# func:logstash 5.4/6.1/6.3 安装
|
||||
@ -26,13 +27,13 @@ echo "3: Install logstash-6.3"
|
||||
echo "4: EXIT"
|
||||
# 选择安装软件版本
|
||||
read -p "Please input your choice:" softversion
|
||||
if [ "${softversion}" == "1" ];then
|
||||
if [ "${softversion}" == "1" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/logstash/logstash-5.4.1.tar.gz"
|
||||
elif [ "${softversion}" == "2" ];then
|
||||
elif [ "${softversion}" == "2" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/logstash/logstash-6.1.3.tar.gz"
|
||||
elif [ "${softversion}" == "3" ];then
|
||||
elif [ "${softversion}" == "3" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/logstash/logstash-6.3.2.tar.gz"
|
||||
elif [ "${softversion}" == "4" ];then
|
||||
elif [ "${softversion}" == "4" ]; then
|
||||
echo "you choce channel!"
|
||||
exit 1;
|
||||
else
|
||||
@ -42,7 +43,7 @@ fi
|
||||
|
||||
# 传入内容,格式化内容输出,可以传入多个参数,用空格隔开
|
||||
output_msg() {
|
||||
for msg in $*;do
|
||||
for msg in $*; do
|
||||
action $msg /bin/true
|
||||
done
|
||||
}
|
||||
@ -51,11 +52,11 @@ output_msg() {
|
||||
# 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称
|
||||
check_yum_command() {
|
||||
output_msg "命令检查:$1"
|
||||
hash $1 >/dev/null 2>&1
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0
|
||||
hash $1 > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 " >> ${install_log_path}${install_log_name} && return 0
|
||||
else
|
||||
yum -y install $2 >/dev/null 2>&1
|
||||
yum -y install $2 > /dev/null 2>&1
|
||||
# hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 }
|
||||
fi
|
||||
}
|
||||
@ -63,8 +64,8 @@ check_yum_command() {
|
||||
# 判断目录是否存在,传入目录绝对路径,可以传入多个目录
|
||||
check_dir() {
|
||||
output_msg "目录检查"
|
||||
for dirname in $*;do
|
||||
[ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1
|
||||
for dirname in $*; do
|
||||
[ -d $dirname ] || mkdir -p $dirname > /dev/null 2>&1
|
||||
echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name}
|
||||
done
|
||||
}
|
||||
@ -73,12 +74,12 @@ check_dir() {
|
||||
download_file() {
|
||||
output_msg "下载源码包"
|
||||
mkdir -p $download_path
|
||||
for file in $*;do
|
||||
for file in $*; do
|
||||
wget $file -c -P $download_path &> /dev/null
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name}
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!" >> ${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!" >> ${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -87,13 +88,13 @@ download_file() {
|
||||
# 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录
|
||||
extract_file() {
|
||||
output_msg "解压源码"
|
||||
for file in $*;do
|
||||
if [ "${file##*.}" == "gz" ];then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ];then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
for file in $*; do
|
||||
if [ "${file##*.}" == "gz" ]; then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path" >> ${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ]; then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path" >> ${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!" >> ${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -101,14 +102,14 @@ extract_file() {
|
||||
# 配置环境变量,第一个参数为添加环境变量的绝对路径
|
||||
config_env() {
|
||||
output_msg "环境变量配置"
|
||||
echo "export PATH=\$PATH:$1" >${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name}
|
||||
echo "export PATH=\$PATH:$1" > ${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!" >> ${install_log_path}${install_log_name}
|
||||
|
||||
}
|
||||
|
||||
# 添加配置文件
|
||||
add_config() {
|
||||
cat> $1 <<EOF
|
||||
cat > $1 << EOF
|
||||
input {
|
||||
beats {
|
||||
port => "5044"
|
||||
@ -124,18 +125,18 @@ EOF
|
||||
}
|
||||
|
||||
main() {
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
|
||||
software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'.tar.gz' '{print $1}')
|
||||
for filename in `ls $download_path`;do
|
||||
software_name=$(echo $URL | awk -F'/' '{print $NF}' | awk -F'.tar.gz' '{print $1}')
|
||||
for filename in `ls $download_path`; do
|
||||
extract_file ${download_path}$filename
|
||||
done
|
||||
rm -fr ${download_path}
|
||||
ln -s $install_path$software_name ${install_path}logstash
|
||||
add_config ${software_config_file}
|
||||
config_env ${install_path}logstash/bin
|
||||
done
|
||||
rm -fr ${download_path}
|
||||
ln -s $install_path$software_name ${install_path}logstash
|
||||
add_config ${software_config_file}
|
||||
config_env ${install_path}logstash/bin
|
||||
}
|
||||
|
||||
main
|
||||
|
@ -28,10 +28,12 @@ printf "${RESET}"
|
||||
|
||||
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"; exit 1; }
|
||||
command -v git >/dev/null 2>&1 || { printf "${RED}Require git 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; }
|
||||
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 "\t sh fastdfs-install.sh [path]\n"
|
||||
printf "\t Example: sh fastdfs-install.sh /opt/fastdfs\n"
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# auth:kaliarch
|
||||
# version:v1.0
|
||||
# func:grafana 5.1.0/5.1.5/5.2.2 安装
|
||||
@ -25,13 +26,13 @@ echo "3: Install grafana 5.2.2"
|
||||
echo "4: EXIT"
|
||||
# 选择安装软件版本
|
||||
read -p "Please input your choice:" softversion
|
||||
if [ "${softversion}" == "1" ];then
|
||||
if [ "${softversion}" == "1" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/grafana/grafana-5.1.0-1.x86_64.rpm"
|
||||
elif [ "${softversion}" == "2" ];then
|
||||
elif [ "${softversion}" == "2" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/grafana/grafana-5.1.5-1.x86_64.rpm"
|
||||
elif [ "${softversion}" == "3" ];then
|
||||
elif [ "${softversion}" == "3" ]; then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/grafana/grafana-5.2.2-1.x86_64.rpm"
|
||||
elif [ "${softversion}" == "4" ];then
|
||||
elif [ "${softversion}" == "4" ]; then
|
||||
echo "you choce channel!"
|
||||
exit 1;
|
||||
else
|
||||
@ -41,7 +42,7 @@ fi
|
||||
|
||||
# 传入内容,格式化内容输出,可以传入多个参数,用空格隔开
|
||||
output_msg() {
|
||||
for msg in $*;do
|
||||
for msg in $*; do
|
||||
action $msg /bin/true
|
||||
done
|
||||
}
|
||||
@ -50,11 +51,11 @@ output_msg() {
|
||||
# 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称
|
||||
check_yum_command() {
|
||||
output_msg "命令检查:$1"
|
||||
hash $1 >/dev/null 2>&1
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0
|
||||
hash $1 > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 " >> ${install_log_path}${install_log_name} && return 0
|
||||
else
|
||||
yum -y install $2 >/dev/null 2>&1
|
||||
yum -y install $2 > /dev/null 2>&1
|
||||
# hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 }
|
||||
fi
|
||||
}
|
||||
@ -62,8 +63,8 @@ check_yum_command() {
|
||||
# 判断目录是否存在,传入目录绝对路径,可以传入多个目录
|
||||
check_dir() {
|
||||
output_msg "目录检查"
|
||||
for dirname in $*;do
|
||||
[ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1
|
||||
for dirname in $*; do
|
||||
[ -d $dirname ] || mkdir -p $dirname > /dev/null 2>&1
|
||||
echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name}
|
||||
done
|
||||
}
|
||||
@ -72,12 +73,12 @@ check_dir() {
|
||||
download_file() {
|
||||
output_msg "下载源码包"
|
||||
mkdir -p $download_path
|
||||
for file in $*;do
|
||||
for file in $*; do
|
||||
wget $file -c -P $download_path &> /dev/null
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name}
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!" >> ${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!" >> ${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -86,24 +87,24 @@ download_file() {
|
||||
install_grafana_plugins() {
|
||||
output_msg "grafana插件安装"
|
||||
check_yum_command grafana-cli
|
||||
grafana-cli plugins install $* >/dev/null
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` grafana plugins $* install success!">>${install_log_path}${install_log_name}
|
||||
grafana-cli plugins install $* > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "`date +%F' '%H:%M:%S` grafana plugins $* install success!" >> ${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%s` grafana plugins $* install success!">>${install_log_path}${install_log_name} && exit 1
|
||||
echo "`date +%F' '%H:%M:%s` grafana plugins $* install success!" >> ${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
|
||||
|
||||
}
|
||||
|
||||
main() {
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
for filename in `ls $download_path`;do
|
||||
yum -y install $download_path$filename >/dev/null 2>&1
|
||||
done
|
||||
install_grafana_plugins alexanderzobnin-zabbix-app
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
for filename in `ls $download_path`; do
|
||||
yum -y install $download_path$filename > /dev/null 2>&1
|
||||
done
|
||||
install_grafana_plugins alexanderzobnin-zabbix-app
|
||||
}
|
||||
|
||||
main
|
||||
|
@ -27,7 +27,8 @@ printf "${RESET}"
|
||||
|
||||
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"; exit 1; }
|
||||
command -v yum > /dev/null 2>&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
|
||||
java -version
|
||||
|
@ -26,9 +26,10 @@ printf "${RESET}"
|
||||
|
||||
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"; exit 1; }
|
||||
command -v java > /dev/null 2>&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 "\t sh kafka-install.sh [version] [path]\n"
|
||||
printf "\t Example: sh kafka-install.sh 2.2.0 /opt/kafka\n"
|
||||
|
@ -28,9 +28,10 @@ printf "${RESET}"
|
||||
|
||||
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"; exit 1; }
|
||||
command -v java > /dev/null 2>&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 "\t sh maven-install.sh [version] [path]\n"
|
||||
printf "\t Example: sh maven-install.sh 3.6.0 /opt/maven\n"
|
||||
|
@ -26,7 +26,7 @@ printf "${RESET}"
|
||||
|
||||
printf "${GREEN}>>>>>>>> install mongodb begin.${RESET}\n"
|
||||
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
|
||||
printf "${PURPLE}[Hint]\n"
|
||||
printf "\t sh mongodb-install.sh [version] [path]\n"
|
||||
printf "\t Example: sh mongodb-install.sh 4.0.9 /opt/mongodb\n"
|
||||
|
@ -26,9 +26,12 @@ printf "${RESET}"
|
||||
|
||||
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"; exit 1; }
|
||||
command -v rpm >/dev/null 2>&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; }
|
||||
command -v wget > /dev/null 2>&1 || { printf "${RED}Require wget but it's not installed.${RESET}\n";
|
||||
exit 1; }
|
||||
command -v rpm > /dev/null 2>&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
|
||||
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
|
||||
|
@ -11,10 +11,12 @@ cat << EOF
|
||||
|
||||
EOF
|
||||
|
||||
command -v java >/dev/null 2>&1 || { echo >&2 "Require java but it's not installed."; exit 1; }
|
||||
command -v mvn >/dev/null 2>&1 || { echo >&2 "Require mvn but it's not installed."; exit 1; }
|
||||
command -v java > /dev/null 2>&1 || { echo >&2 "Require java but it's not installed.";
|
||||
exit 1; }
|
||||
command -v mvn > /dev/null 2>&1 || { echo >&2 "Require mvn but it's not installed.";
|
||||
exit 1; }
|
||||
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
|
||||
echo "Usage: sh nacos-install.sh [version] [path]"
|
||||
printf "Example: sh nacos-install.sh 1.0.0 /opt/nacos\n"
|
||||
fi
|
||||
|
@ -27,9 +27,10 @@ printf "${RESET}"
|
||||
|
||||
printf "${GREEN}>>>>>>>> install maven begin.${RESET}\n"
|
||||
|
||||
command -v yum >/dev/null 2>&1 || { printf "${RED}Require yum 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; }
|
||||
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
|
||||
printf "${PURPLE}[Hint]\n"
|
||||
printf "\t sh nginx-install.sh [version] [path]\n"
|
||||
printf "\t Example: sh nginx-install.sh 1.16.0 /opt/nginx\n"
|
||||
|
@ -27,7 +27,7 @@ printf "${RESET}"
|
||||
|
||||
printf "${GREEN}>>>>>>>> install nodejs begin.${RESET}\n"
|
||||
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
|
||||
printf "${PURPLE}[Hint]\n"
|
||||
printf "\t sh nodejs-install.sh [version]\n"
|
||||
printf "\t Example: sh nodejs-install.sh 10.15.2\n"
|
||||
|
@ -24,9 +24,10 @@ cat << EOF
|
||||
EOF
|
||||
printf "${RESET}"
|
||||
|
||||
command -v yum >/dev/null 2>&1 || { printf "${RED}Require yum 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; }
|
||||
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]] || [[ $# -lt 3 ]] || [[ $# -lt 4 ]];then
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]] || [[ $# -lt 3 ]] || [[ $# -lt 4 ]]; then
|
||||
echo "Usage: sh redis-install.sh [version] [path] [port] [password]"
|
||||
echo -e "Example: sh redis-install.sh 5.0.4 /opt/redis 6379 123456\n"
|
||||
fi
|
||||
|
@ -26,7 +26,7 @@ printf "${RESET}"
|
||||
|
||||
printf "${GREEN}>>>>>>>> install tomcat begin.${RESET}\n"
|
||||
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
|
||||
printf "${PURPLE}[Hint]\n"
|
||||
printf "\t sh rocketmq-install.sh [version] [path]\n"
|
||||
printf "\t Example: sh rocketmq-install.sh 4.5.0 /opt/rocketmq\n"
|
||||
|
@ -26,7 +26,7 @@ printf "${RESET}"
|
||||
|
||||
printf "${GREEN}>>>>>>>> install tomcat begin.${RESET}\n"
|
||||
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
|
||||
printf "${PURPLE}[Hint]\n"
|
||||
printf "\t sh tomcat8-install.sh [version] [path]\n"
|
||||
printf "\t Example: sh tomcat8-install.sh 8.5.28 /opt/tomcat8\n"
|
||||
|
@ -26,7 +26,7 @@ printf "${RESET}"
|
||||
|
||||
printf "${GREEN}>>>>>>>> install zookeeper begin.${RESET}\n"
|
||||
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then
|
||||
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
|
||||
printf "${PURPLE}[Hint]\n"
|
||||
printf "\t sh zookeeper-install.sh [version] [path]\n"
|
||||
printf "\t Example: sh zookeeper-install.sh 3.4.12 /opt/zookeeper\n"
|
||||
|
@ -27,8 +27,10 @@ printf "${RESET}"
|
||||
|
||||
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"; exit 1; }
|
||||
command -v git >/dev/null 2>&1 || { printf "${RED}Require git 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; }
|
||||
command -v git > /dev/null 2>&1 || { printf "${RED}Require git but it's not installed.${RESET}\n";
|
||||
exit 1; }
|
||||
|
||||
# install zsh
|
||||
yum install -y zsh
|
||||
|
@ -11,18 +11,18 @@ function getDeviceIp() {
|
||||
}
|
||||
|
||||
function setDNSServer() {
|
||||
echo -e "设置DNS服务器"
|
||||
cat >> /etc/resolv.conf << EOF
|
||||
echo -e "设置DNS服务器"
|
||||
cat >> /etc/resolv.conf << EOF
|
||||
nameserver 114.114.114.114
|
||||
nameserver 8.8.8.8
|
||||
EOF
|
||||
}
|
||||
|
||||
function setHosts() {
|
||||
getDeviceIp
|
||||
host=`hostname`
|
||||
cat >> /etc/hosts << EOF
|
||||
${ip} ${host}
|
||||
getDeviceIp
|
||||
host=`hostname`
|
||||
cat >> /etc/hosts << EOF
|
||||
${ip} ${host}
|
||||
EOF
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
printHeadInfo() {
|
||||
cat << EOF
|
||||
cat << EOF
|
||||
###################################################################################
|
||||
# Linux Centos7 系统配置脚本(根据需要选择)
|
||||
# @author: Zhang Peng
|
||||
@ -11,14 +11,14 @@ EOF
|
||||
}
|
||||
|
||||
setLimit() {
|
||||
cat >> /etc/security/limits.conf << EOF
|
||||
cat >> /etc/security/limits.conf << EOF
|
||||
* - nofile 65535
|
||||
* - nproc 65535
|
||||
EOF
|
||||
}
|
||||
|
||||
setLang() {
|
||||
cat > /etc/sysconfig/i18n << EOF
|
||||
cat > /etc/sysconfig/i18n << EOF
|
||||
LANG="zh_CN.UTF-8"
|
||||
EOF
|
||||
}
|
||||
@ -48,10 +48,10 @@ setBootMode() {
|
||||
}
|
||||
|
||||
# 配置 IPv4
|
||||
configIpv4(){
|
||||
echo "配置 ipv4"
|
||||
configIpv4() {
|
||||
echo "配置 ipv4"
|
||||
|
||||
cat >> /etc/sysctl.conf << EOF
|
||||
cat >> /etc/sysctl.conf << EOF
|
||||
net.ipv4.tcp_tw_reuse = 1
|
||||
net.ipv4.tcp_tw_recycle = 1
|
||||
net.ipv4.tcp_fin_timeout = 2
|
||||
@ -78,23 +78,23 @@ EOF
|
||||
|
||||
# 关闭 IPv6
|
||||
closeIpv6() {
|
||||
echo "关闭 ipv6"
|
||||
echo "关闭 ipv6"
|
||||
|
||||
cat > /etc/modprobe.d/ipv6.conf << EOF
|
||||
cat > /etc/modprobe.d/ipv6.conf << EOF
|
||||
alias net-pf-10 off
|
||||
options ipv6 disable=1
|
||||
EOF
|
||||
|
||||
echo "NETWORKING_IPV6=off" >> /etc/sysconfig/network
|
||||
echo "NETWORKING_IPV6=off" >> /etc/sysconfig/network
|
||||
}
|
||||
|
||||
# 入口函数
|
||||
main() {
|
||||
PS3="请选择要执行的操作:"
|
||||
select ITEM in "设置 DNS" "设置 NTP" "关闭防火墙" "配置 IPv4" "关闭 IPv6" "全部执行"
|
||||
do
|
||||
PS3="请选择要执行的操作:"
|
||||
select ITEM in "设置 DNS" "设置 NTP" "关闭防火墙" "配置 IPv4" "关闭 IPv6" "全部执行"
|
||||
do
|
||||
|
||||
case ${ITEM} in
|
||||
case ${ITEM} in
|
||||
"设置 DNS")
|
||||
curl -o- https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/sys/set-dns.sh | bash
|
||||
;;
|
||||
@ -121,13 +121,14 @@ case ${ITEM} in
|
||||
echo -e "输入项不支持!"
|
||||
main
|
||||
;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
esac
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
filepath=$(cd "$(dirname "$0")"; pwd)
|
||||
filepath=$(cd "$(dirname "$0")";
|
||||
pwd)
|
||||
|
||||
printHeadInfo
|
||||
main
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#mail:xuel@anchnet.com
|
||||
#data:2017/9/7
|
||||
#AutoInstall ELK scripts
|
||||
@ -15,35 +16,36 @@ elasticsearch_url="https://artifacts.elastic.co/downloads/elasticsearch/elastics
|
||||
kibana_url="https://artifacts.elastic.co/downloads/kibana/kibana-5.4.1-linux-x86_64.tar.gz"
|
||||
logstash_url="https://artifacts.elastic.co/downloads/logstash/logstash-5.4.1.tar.gz"
|
||||
filebeat_url="https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.4.1-linux-x86_64.tar.gz"
|
||||
sys_version=`cat /etc/redhat-release |awk '{print $4}'|cut -d. -f1`
|
||||
IP=`ip addr|grep "inet "|grep -v 127.0.0.1|awk '{print $2}'|cut -d/ -f1`
|
||||
sys_version=`cat /etc/redhat-release | awk '{print $4}' | cut -d. -f1`
|
||||
IP=`ip addr | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}' | cut -d/ -f1`
|
||||
jvm_conf="/usr/local/elasticsearch/config/jvm.options"
|
||||
sys_mem=`free -m|grep Mem:|awk '{print $2}'|awk '{sum+=$1} END {print sum/1024}'|cut -d. -f1`
|
||||
sys_mem=`free -m | grep Mem: | awk '{print $2}' | awk '{sum+=$1} END {print sum/1024}' | cut -d. -f1`
|
||||
|
||||
#wget software
|
||||
wget_fun() {
|
||||
if [ ! -d ${software_dir} ];then
|
||||
if [ ! -d ${software_dir} ]; then
|
||||
mkdir -p ${software_dir} && cd ${software_dir}
|
||||
else
|
||||
else
|
||||
cd ${software_dir}
|
||||
fi
|
||||
for software in $elasticsearch_url $kibana_url $logstash_url $filebeat_url
|
||||
do
|
||||
fi
|
||||
for software in $elasticsearch_url $kibana_url $logstash_url $filebeat_url
|
||||
do
|
||||
wget -c $software
|
||||
done
|
||||
clear
|
||||
done
|
||||
clear
|
||||
}
|
||||
|
||||
#initial system:install java wget;set hostname;disable firewalld
|
||||
init_sys() {
|
||||
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
|
||||
[ "${sys_version}" != "7" ] && echo "Error:This Scripts Support Centos7.xx" && exit 1
|
||||
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
|
||||
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
|
||||
setenforce 0
|
||||
yum install -y java-1.8.0-openjdk wget net-tools
|
||||
hostnamectl set-hostname elk-server
|
||||
systemctl stop firewalld
|
||||
cat >>/etc/security/limits.conf<<EOF
|
||||
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
|
||||
[ "${sys_version}" != "7" ] && echo "Error:This Scripts Support Centos7.xx" && exit 1
|
||||
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
|
||||
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
|
||||
setenforce 0
|
||||
yum install -y java-1.8.0-openjdk wget net-tools
|
||||
hostnamectl set-hostname elk-server
|
||||
systemctl stop firewalld
|
||||
cat >> /etc/security/limits.conf << EOF
|
||||
* soft nofile 65536
|
||||
* hard nofile 65536
|
||||
* soft nGproc 65536
|
||||
@ -53,21 +55,21 @@ EOF
|
||||
|
||||
#install elasticsearch
|
||||
install_elasticsearch() {
|
||||
cd $software_dir
|
||||
tar zxf elasticsearch-5.4.1.tar.gz
|
||||
mv elasticsearch-5.4.1 /usr/local/elasticsearch
|
||||
mkdir -p /usr/local/elasticsearch/data /usr/local/elasticsearch/logs
|
||||
useradd elasticsearch
|
||||
chown -R elasticsearch:elasticsearch /usr/local/elasticsearch
|
||||
echo "vm.max_map_count = 655360" >>/etc/sysctl.conf && sysctl -p
|
||||
if [ ${sys_mem} -eq 0 ];then
|
||||
cd $software_dir
|
||||
tar zxf elasticsearch-5.4.1.tar.gz
|
||||
mv elasticsearch-5.4.1 /usr/local/elasticsearch
|
||||
mkdir -p /usr/local/elasticsearch/data /usr/local/elasticsearch/logs
|
||||
useradd elasticsearch
|
||||
chown -R elasticsearch:elasticsearch /usr/local/elasticsearch
|
||||
echo "vm.max_map_count = 655360" >> /etc/sysctl.conf && sysctl -p
|
||||
if [ ${sys_mem} -eq 0 ]; then
|
||||
sed -i "s#`grep "^-Xmx" ${jvm_conf}`#"-Xmx512m"#g" ${jvm_conf}
|
||||
sed -i "s#`grep "^-Xms" ${jvm_conf}`#"-Xms512m"#g" ${jvm_conf}
|
||||
else
|
||||
else
|
||||
sed -i "s#`grep "^-Xmx" ${jvm_conf}`#"-Xmx${sys_mem}g"#g" ${jvm_conf}
|
||||
sed -i "s#`grep "^-Xms" ${jvm_conf}`#"-Xms${sys_mem}g"#g" ${jvm_conf}
|
||||
fi
|
||||
cat >>/usr/local/elasticsearch/config/elasticsearch.yml<<EOF
|
||||
fi
|
||||
cat >> /usr/local/elasticsearch/config/elasticsearch.yml << EOF
|
||||
cluster.name: my-application
|
||||
node.name: elk-server
|
||||
path.data: /usr/local/elasticsearch/data
|
||||
@ -76,15 +78,15 @@ network.host: 127.0.0.1
|
||||
http.port: 9200
|
||||
discovery.zen.ping.unicast.hosts: ["elk-server"]
|
||||
EOF
|
||||
su - elasticsearch -c "nohup /usr/local/elasticsearch/bin/elasticsearch &"
|
||||
su - elasticsearch -c "nohup /usr/local/elasticsearch/bin/elasticsearch &"
|
||||
}
|
||||
|
||||
#install logstash
|
||||
install_logstash() {
|
||||
cd $software_dir
|
||||
tar -zxf logstash-5.4.1.tar.gz
|
||||
mv logstash-5.4.1 /usr/local/logstash
|
||||
cat>/usr/local/logstash/config/01-syslog.conf<<EOF
|
||||
cd $software_dir
|
||||
tar -zxf logstash-5.4.1.tar.gz
|
||||
mv logstash-5.4.1 /usr/local/logstash
|
||||
cat > /usr/local/logstash/config/01-syslog.conf << EOF
|
||||
input {
|
||||
beats {
|
||||
port => "5044"
|
||||
@ -97,15 +99,15 @@ output {
|
||||
stdout { codec => rubydebug }
|
||||
}
|
||||
EOF
|
||||
nohup /usr/local/logstash/bin/logstash -f /usr/local/logstash/config/01-syslog.conf & >/dev/null
|
||||
nohup /usr/local/logstash/bin/logstash -f /usr/local/logstash/config/01-syslog.conf & > /dev/null
|
||||
}
|
||||
|
||||
#install filebeat
|
||||
install_filebeat() {
|
||||
cd $software_dir
|
||||
tar -zxf filebeat-5.4.1-linux-x86_64.tar.gz
|
||||
mv filebeat-5.4.1-linux-x86_64 /usr/local/filebeat
|
||||
cat >/usr/local/filebeat/filebeat.yml<<EOF
|
||||
cd $software_dir
|
||||
tar -zxf filebeat-5.4.1-linux-x86_64.tar.gz
|
||||
mv filebeat-5.4.1-linux-x86_64 /usr/local/filebeat
|
||||
cat > /usr/local/filebeat/filebeat.yml << EOF
|
||||
filebeat.prospectors:
|
||||
- input_type: log
|
||||
paths:
|
||||
@ -113,52 +115,53 @@ filebeat.prospectors:
|
||||
output.logstash:
|
||||
hosts: ["127.0.0.1:5044"]
|
||||
EOF
|
||||
cd /usr/local/filebeat/
|
||||
nohup /usr/local/filebeat/filebeat & >/dev/null
|
||||
cd /usr/local/filebeat/
|
||||
nohup /usr/local/filebeat/filebeat & > /dev/null
|
||||
}
|
||||
|
||||
#install kibana
|
||||
install_kibana() {
|
||||
cd $software_dir
|
||||
tar -zxf kibana-5.4.1-linux-x86_64.tar.gz
|
||||
mv kibana-5.4.1-linux-x86_64 /usr/local/kibana
|
||||
cat >> /usr/local/kibana/config/kibana.yml <<EOF
|
||||
cd $software_dir
|
||||
tar -zxf kibana-5.4.1-linux-x86_64.tar.gz
|
||||
mv kibana-5.4.1-linux-x86_64 /usr/local/kibana
|
||||
cat >> /usr/local/kibana/config/kibana.yml << EOF
|
||||
server.port: 5601
|
||||
server.host: "0.0.0.0"
|
||||
elasticsearch.url: "http://127.0.0.1:9200"
|
||||
EOF
|
||||
nohup /usr/local/kibana/bin/kibana & >/dev/null
|
||||
nohup /usr/local/kibana/bin/kibana & > /dev/null
|
||||
}
|
||||
|
||||
check() {
|
||||
port=$1
|
||||
program=$2
|
||||
check_port=`netstat -lntup|grep ${port}|wc -l`
|
||||
check_program=`ps -ef|grep ${program}|grep -v grep|wc -l`
|
||||
if [ $check_port -gt 0 ] && [ $check_program -gt 0 ];then
|
||||
port=$1
|
||||
program=$2
|
||||
check_port=`netstat -lntup | grep ${port} | wc -l`
|
||||
check_program=`ps -ef | grep ${program} | grep -v grep | wc -l`
|
||||
if [ $check_port -gt 0 ] && [ $check_program -gt 0 ]; then
|
||||
action "${program} run is ok!" /bin/true
|
||||
else
|
||||
else
|
||||
action "${program} run is error!" /bin/false
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
init_sys
|
||||
wget_fun
|
||||
install_elasticsearch
|
||||
install_filebeat
|
||||
install_logstash
|
||||
install_kibana
|
||||
echo -e "\033[32m Checking Elasticsearch...\033[0m"
|
||||
sleep 20
|
||||
check :9200 "elasticsearch"
|
||||
echo -e "\033[32m Checking Logstash...\033[0m"
|
||||
sleep 2
|
||||
check ":9600" "logstash"
|
||||
echo -e "\033[32m Checking Kibana...\033[0m"
|
||||
sleep 2
|
||||
check ":5601" "kibana"
|
||||
action "ELK install is success!" /bin/true
|
||||
echo "url:http://$IP:5601"
|
||||
init_sys
|
||||
wget_fun
|
||||
install_elasticsearch
|
||||
install_filebeat
|
||||
install_logstash
|
||||
install_kibana
|
||||
echo -e "\033[32m Checking Elasticsearch...\033[0m"
|
||||
sleep 20
|
||||
check :9200 "elasticsearch"
|
||||
echo -e "\033[32m Checking Logstash...\033[0m"
|
||||
sleep 2
|
||||
check ":9600" "logstash"
|
||||
echo -e "\033[32m Checking Kibana...\033[0m"
|
||||
sleep 2
|
||||
check ":5601" "kibana"
|
||||
action "ELK install is success!" /bin/true
|
||||
echo "url:http://$IP:5601"
|
||||
}
|
||||
|
||||
main
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# auth:kaliarch
|
||||
# func:sys info check
|
||||
# version:v1.0
|
||||
@ -16,7 +17,7 @@ LIMIT_CPU=85
|
||||
LOG_DIR=/var/log/cpulimit/
|
||||
|
||||
# 超过阀值进程pid
|
||||
PIDARG=$(ps -aux |awk -v CPU=${PEC_CPU} '{if($3 > CPU) print $2}')
|
||||
PIDARG=$(ps -aux | awk -v CPU=${PEC_CPU} '{if($3 > CPU) print $2}')
|
||||
CPULIMITCMD=$(which cpulimit)
|
||||
|
||||
install_cpulimit() {
|
||||
@ -29,21 +30,21 @@ install_cpulimit() {
|
||||
|
||||
|
||||
do_cpulimit() {
|
||||
[ ! -d ${LOG_DIR} ] && mkdir -p ${LOG_DIR}
|
||||
for i in ${PIDARG};
|
||||
do
|
||||
MSG=$(ps -aux |awk -v pid=$i '{if($2 == pid) print $0}')
|
||||
[ ! -d ${LOG_DIR} ] && mkdir -p ${LOG_DIR}
|
||||
for i in ${PIDARG};
|
||||
do
|
||||
MSG=$(ps -aux | awk -v pid=$i '{if($2 == pid) print $0}')
|
||||
echo ${MSG}
|
||||
[ ! -d /tmp ] && mkdir /tmp || cd /tmp
|
||||
nohup ${CPULIMITCMD} -p $i -l ${LIMIT_CPU} &
|
||||
echo "$(date) -- ${MSG}" >> ${LOG_DIR}$(date +%F).log
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
hash cpulimit
|
||||
if [ $? -eq 0 ];then
|
||||
if [ $? -eq 0 ]; then
|
||||
do_cpulimit
|
||||
else
|
||||
install_cpulimit && do_cpulimit
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# function:自定义rm命令,每天晚上定时清理
|
||||
|
||||
CMD_SCRIPTS=$HOME/.rm_scripts.sh
|
||||
@ -7,7 +8,7 @@ CRON_FILE=/var/spool/cron/root
|
||||
BASHRC=$HOME/.bashrc
|
||||
|
||||
[ ! -d ${TRASH_DIR} ] && mkdir -p ${TRASH_DIR}
|
||||
cat > $CMD_SCRIPTS <<EOF
|
||||
cat > $CMD_SCRIPTS << EOF
|
||||
PARA_CNT=\$#
|
||||
TRASH_DIR=$TRASH_DIR
|
||||
for i in \$*; do
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Daily_Archive - Archive designated files & directories
|
||||
######################################################
|
||||
@ -54,7 +55,7 @@ do
|
||||
echo "Continuing to build archive file."
|
||||
echo
|
||||
fi
|
||||
#
|
||||
#
|
||||
FILE_NO=$[ $FILE_NO + 1 ] # Increase Line/File number by one
|
||||
read FILE_NAME # Read next record.
|
||||
done
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Hourly_Archive - Every hour create an archive
|
||||
######################################################
|
||||
@ -61,7 +62,7 @@ do
|
||||
echo "Continuing to build archive file."
|
||||
echo
|
||||
fi
|
||||
#
|
||||
#
|
||||
FILE_NO=$[ $FILE_NO + 1 ] # Increase Line/File number by one
|
||||
read FILE_NAME # Read next record.
|
||||
done
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Delete_User - Automates the 4 steps to remove an account
|
||||
#
|
||||
@ -8,15 +9,16 @@
|
||||
#
|
||||
#################################################################
|
||||
function get_answer {
|
||||
#
|
||||
#
|
||||
unset ANSWER
|
||||
ASK_COUNT=0
|
||||
#
|
||||
#
|
||||
while [ -z "$ANSWER" ] # while no answer is given, keep asking
|
||||
do
|
||||
ASK_COUNT=$[ $ASK_COUNT + 1 ]
|
||||
#
|
||||
case $ASK_COUNT in # If user gives no answer in time allowed
|
||||
#
|
||||
case $ASK_COUNT in
|
||||
# If user gives no answer in time allowed
|
||||
2)
|
||||
echo
|
||||
echo "Please answer the question."
|
||||
@ -36,33 +38,36 @@ function get_answer {
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
#
|
||||
#
|
||||
echo
|
||||
#
|
||||
#
|
||||
if [ -n "$LINE2" ]
|
||||
then
|
||||
echo $LINE1 # Print 2 lines
|
||||
echo -e $LINE2" \c"
|
||||
else # Print 1 line
|
||||
else
|
||||
# Print 1 line
|
||||
echo -e $LINE1" \c"
|
||||
fi
|
||||
#
|
||||
# Allow 60 seconds to answer before time-out
|
||||
#
|
||||
# Allow 60 seconds to answer before time-out
|
||||
read -t 60 ANSWER
|
||||
done
|
||||
#
|
||||
# Do a little variable clean-up
|
||||
#
|
||||
#
|
||||
# Do a little variable clean-up
|
||||
#
|
||||
unset LINE1
|
||||
unset LINE2
|
||||
#
|
||||
} #end of get_answer function
|
||||
#
|
||||
}
|
||||
|
||||
#end of get_answer function
|
||||
#
|
||||
#################################################################
|
||||
function process_answer {
|
||||
#
|
||||
#
|
||||
case $ANSWER in
|
||||
y|Y|YES|yes|yEs|yeS|YEs|yES)
|
||||
y | Y | YES | yes | yEs | yeS | YEs | yES)
|
||||
# If user answers "yes".do nothing.
|
||||
;;
|
||||
*)
|
||||
@ -78,8 +83,10 @@ function process_answer {
|
||||
# Do a little variable clean-up
|
||||
unset EXIT_LINE1
|
||||
unset EXIT_LINE2
|
||||
#
|
||||
} #End of process_answer function
|
||||
#
|
||||
}
|
||||
|
||||
#End of process_answer function
|
||||
#
|
||||
################################################################
|
||||
#
|
||||
@ -146,12 +153,12 @@ echo
|
||||
ps -u $USER_ACCOUNT #List the processes running
|
||||
#
|
||||
case $? in
|
||||
1) # No processes running for this User Account
|
||||
1) # No processes running for this User Account
|
||||
#
|
||||
echo "There are no processes for this account currently running."
|
||||
echo
|
||||
;;
|
||||
0) # Processes running for this User Account.
|
||||
;;
|
||||
0) # Processes running for this User Account.
|
||||
# Ask Script User if wants us to kill the processes.
|
||||
#
|
||||
unset ANSWER # I think this line is not needed
|
||||
@ -159,14 +166,14 @@ case $? in
|
||||
get_answer
|
||||
#
|
||||
case $ANSWER in
|
||||
y|Y|YES|yes|Yes|yEs|yeS|YEs|yES) # if user answer "yes",
|
||||
y | Y | YES | yes | Yes | yEs | yeS | YEs | yES) # if user answer "yes",
|
||||
#kill User Account processes
|
||||
#
|
||||
echo
|
||||
#
|
||||
# Clean-up temp file upon signals
|
||||
#
|
||||
trap "rm $USER_ACCOUNT_Running_Process.rpt" SIGTERM SIGINT SIGQUIT
|
||||
trap "rm$USER_ACCOUNT_Running_Process.rpt" SIGTERM SIGINT SIGQUIT
|
||||
#
|
||||
# List user processes running
|
||||
ps -u $USER_ACCOUNT > $USER_ACCOUNT_Running_Process.rpt
|
||||
@ -179,7 +186,7 @@ case $? in
|
||||
while [ $? -eq 0 ]
|
||||
do
|
||||
# obtain PID
|
||||
USER_PID=$(echo $USER_PROCESS_REC | cut -d " " -f1 )
|
||||
USER_PID=$(echo $USER_PROCESS_REC | cut -d " " -f1)
|
||||
kill -9 $USER_PID
|
||||
echo "Killed process $USER_PID"
|
||||
read USER_PROCESS_REC
|
||||
@ -195,7 +202,7 @@ case $? in
|
||||
echo
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
;;
|
||||
esac
|
||||
###################################################################################
|
||||
#
|
||||
@ -216,7 +223,7 @@ echo "Please wait. This may take a while..."
|
||||
REPORT_DATE=`date +%y%m%d`
|
||||
REPORT_FILE=$USER_ACCOUNT"_Files_"$REPORT_DATE".rpt"
|
||||
#
|
||||
find / -user $USER_ACCOUNT > $REPORT_FILE 2>/dev/null
|
||||
find / -user $USER_ACCOUNT > $REPORT_FILE 2> /dev/null
|
||||
#
|
||||
echo
|
||||
echo "Report is complete."
|
||||
|
@ -11,7 +11,7 @@ for DIR in ${DIRS}
|
||||
do
|
||||
echo ""
|
||||
echo "The ${DIR} Directory:"
|
||||
du -S ${DIR} 2>/dev/null |
|
||||
du -S ${DIR} 2> /dev/null |
|
||||
sort -rn |
|
||||
sed '{11,$D; =}' |
|
||||
sed 'N; s/\n/ /' |
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
################### 读取脚本输入参数并校验 ###################
|
||||
declare -a serial
|
||||
serial=(start stop restart)
|
||||
serial=( start stop restart )
|
||||
echo -n "请选择操作(可选值:start|stop|restart):"
|
||||
read oper
|
||||
if ! echo ${serial[@]} | grep -q ${oper}; then
|
||||
@ -16,7 +16,7 @@ if ! echo ${serial[@]} | grep -q ${oper}; then
|
||||
fi
|
||||
|
||||
declare -a serial2
|
||||
serial2=(dev test prod)
|
||||
serial2=( dev test prod )
|
||||
echo -n "请选择运行环境(可选值:dev|test|prod):"
|
||||
read profile
|
||||
if ! echo ${serial2[@]} | grep -q ${profile}; then
|
||||
|
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
current_dir=$(cd `dirname $0`; pwd)
|
||||
current_dir=$(cd `dirname $0`;
|
||||
pwd)
|
||||
echo "当前目录是:${current_dir}"
|
||||
|
||||
parent_dir=$(dirname $(pwd))
|
||||
|
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# 创建数组
|
||||
nums=([2]=2 [0]=0 [1]=1)
|
||||
colors=(red yellow "dark blue")
|
||||
nums=( [ 2 ] = 2 [ 0 ] = 0 [ 1 ] = 1 )
|
||||
colors=( red yellow "dark blue" )
|
||||
|
||||
# 访问数组的单个元素
|
||||
echo ${nums[1]}
|
||||
@ -43,13 +43,13 @@ echo ${#nums[*]}
|
||||
# 3
|
||||
|
||||
# 向数组中添加元素
|
||||
colors=(white "${colors[@]}" green black)
|
||||
colors=( white "${colors[@]}" green black )
|
||||
echo ${colors[@]}
|
||||
# Output:
|
||||
# white red yellow dark blue green black
|
||||
|
||||
# 从数组中删除元素
|
||||
unset nums[0]
|
||||
unset nums[ 0 ]
|
||||
echo ${nums[@]}
|
||||
# Output:
|
||||
# 1 2
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
########## 这是分割线 ##########
|
||||
|
||||
:<<EOF
|
||||
: << EOF
|
||||
echo '这是多行注释'
|
||||
echo '这是多行注释'
|
||||
echo '这是多行注释'
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# 开启 debug
|
||||
set -x
|
||||
for (( i = 0; i < 3; i++ )); do
|
||||
for (( i = 0; i < 3; i ++ )); do
|
||||
printf ${i}
|
||||
done
|
||||
# 关闭 debug
|
||||
@ -21,6 +21,8 @@ set +x
|
||||
# + (( i < 3 ))
|
||||
# + set +x
|
||||
|
||||
for i in {1..5}; do printf ${i}; done
|
||||
for i in {1..5}; do
|
||||
printf ${i};
|
||||
done
|
||||
printf "\n"
|
||||
# Output: 12345
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
calc(){
|
||||
calc() {
|
||||
PS3="choose the oper: "
|
||||
select oper in + - \* / # 生成操作符选择菜单
|
||||
do
|
||||
@ -28,6 +28,7 @@ calc(){
|
||||
break
|
||||
done
|
||||
}
|
||||
|
||||
calc
|
||||
echo "the result is: $?" # $? 获取 calc 函数返回值
|
||||
# $ ./function-demo.sh
|
||||
|
@ -16,8 +16,9 @@ else
|
||||
echo "第二个参数为空"
|
||||
fi
|
||||
|
||||
paramsFunction(){
|
||||
paramsFunction() {
|
||||
echo "函数第一个入参:$1"
|
||||
echo "函数第二个入参:$2"
|
||||
}
|
||||
|
||||
paramsFunction ${x} ${y}
|
||||
|
@ -5,7 +5,7 @@ runner() {
|
||||
}
|
||||
|
||||
name=zp
|
||||
paramsFunction(){
|
||||
paramsFunction() {
|
||||
echo "函数第一个入参:$1"
|
||||
echo "函数第二个入参:$2"
|
||||
echo "传递到脚本的参数个数:$#"
|
||||
@ -19,6 +19,7 @@ paramsFunction(){
|
||||
runner
|
||||
echo "runner 函数的返回值:$?"
|
||||
}
|
||||
|
||||
paramsFunction 1 "abc" "hello, \"zp\""
|
||||
# Output:
|
||||
# 函数第一个入参:1
|
||||
|
@ -1,2 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Hello, world!"
|
||||
|
@ -20,7 +20,9 @@ done
|
||||
|
||||
################### for in 语句 ###################
|
||||
echo "print 1 to 5"
|
||||
for i in {1..5}; do echo ${i}; done
|
||||
for i in {1..5}; do
|
||||
echo ${i};
|
||||
done
|
||||
# Output:
|
||||
# print 1 to 5
|
||||
# 1
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
################### if 语句 ###################
|
||||
# 写成一行
|
||||
if [[ 1 -eq 1 ]]; then echo "1 -eq 1 result is: true"; fi
|
||||
if [[ 1 -eq 1 ]]; then
|
||||
echo "1 -eq 1 result is: true";
|
||||
fi
|
||||
# Output: 1 -eq 1 result is: true
|
||||
|
||||
# 写成多行
|
||||
|
@ -47,7 +47,7 @@ echo "key is ${key}"
|
||||
|
||||
################### 判断字符串中是否包含子字符串 ###################
|
||||
result=$(echo "${str}" | grep "feature/")
|
||||
if [[ "$result" != "" ]] ; then
|
||||
if [[ "$result" != "" ]]; then
|
||||
echo "feature/ 是 ${str} 的子字符串"
|
||||
else
|
||||
echo "feature/ 不是 ${str} 的子字符串"
|
||||
|
@ -6,7 +6,7 @@ database='test'
|
||||
|
||||
for f in `ls */*.sql`
|
||||
do
|
||||
echo ${f};
|
||||
mysql -u${user} -p${password} -f ${database} -e "source $f";
|
||||
echo ${f};
|
||||
mysql -u${user} -p${password} -f ${database} -e "source $f";
|
||||
done
|
||||
echo 'OK!'
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# send data to the the table in the MYSQL database
|
||||
|
||||
MYSQL=`which mysql`
|
||||
@ -9,7 +10,7 @@ then
|
||||
else
|
||||
#脚本变量一定要用双引号,字符串变量使用单引号
|
||||
statement=" insert into em_admin values(NULL, '$1', $2)"
|
||||
$MYSQL emwjs -u test <<EOF
|
||||
$MYSQL emwjs -u test << EOF
|
||||
$statement
|
||||
EOF
|
||||
if [ $? -eq 0 ]
|
||||
|
@ -1,13 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
#连接数据库
|
||||
mysql=`which mysql
|
||||
`
|
||||
mysql=`which mysql`
|
||||
#发送单个命令
|
||||
$mysql emwjs -u test -e "show databases;"
|
||||
|
||||
#发送多个命令
|
||||
$mysql emwjs -u test <<EOF
|
||||
$mysql emwjs -u test << EOF
|
||||
show tables;
|
||||
select * from em_admin;
|
||||
EOF
|
||||
|
@ -1,8 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
#退出状态码,最大为255,超过则进行模运算
|
||||
#testing the exit status
|
||||
var1=10
|
||||
var2=20
|
||||
var3=$[ $var1 + $var2]
|
||||
var3=$[ $var1 + $var2 ]
|
||||
echo The answer is $var3
|
||||
exit 5
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#An example of using the expr command
|
||||
|
||||
var1=10
|
||||
|
@ -5,7 +5,7 @@ var2=43.67
|
||||
var3=33.2
|
||||
var4=71
|
||||
|
||||
var5=`bc <<EOF
|
||||
var5=`bc << EOF
|
||||
scale=4
|
||||
a1 = $var1 * $var2
|
||||
b1 = $var3 * $var4
|
||||
|
@ -3,5 +3,5 @@
|
||||
var1=10
|
||||
var2=50
|
||||
var3=45
|
||||
var4=$[$var1 * ($var2 - $var3)]
|
||||
var4=$[ $var1 * ( $var2 - $var3 ) ]
|
||||
echo 'The final result is '$var4
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#using the backtick character 会把反引号里面当作一条命令来执行
|
||||
|
||||
testing=`date`
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
var1=100
|
||||
var2=45
|
||||
var3=`echo "scale=4; $var1 / $var2" | bc`
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#This script displays the date and who's logged on
|
||||
|
||||
#如果想在同一行显示
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#display user information from system
|
||||
|
||||
echo "User info fro userId:$USER"
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#copy the /usr/bin directory listing to a log file
|
||||
|
||||
today=`date +%y%m%d`
|
||||
|
@ -7,7 +7,7 @@
|
||||
str="0.0.0.1"
|
||||
OLD_IFS="$IFS"
|
||||
IFS="."
|
||||
array=(${str})
|
||||
array=( ${str} )
|
||||
IFS="$OLD_IFS"
|
||||
size=${#array[*]}
|
||||
lastIndex=`expr ${size} - 1`
|
||||
|
@ -48,7 +48,7 @@ echo "version is ${version}"
|
||||
|
||||
################### 判断字符串中是否包含子字符串 ###################
|
||||
result=$(echo "${str}" | grep "feature/")
|
||||
if [[ "$result" != "" ]] ; then
|
||||
if [[ "$result" != "" ]]; then
|
||||
echo "feature/ 是 ${str} 的子字符串"
|
||||
else
|
||||
echo "feature/ 不是 ${str} 的子字符串"
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# testing signal trapping
|
||||
|
||||
trap "echo 'Sorry! I have trapped Ctrl-C'" SIGINT SIGTERM
|
||||
trap "echo'Sorry! I have trapped Ctrl-C'" SIGINT SIGTERM
|
||||
|
||||
echo this is a test program
|
||||
|
||||
@ -12,5 +12,5 @@ while [ $count -le 10 ]
|
||||
do
|
||||
echo "Loop #$count"
|
||||
sleep 5
|
||||
count=$[ $count+1 ]
|
||||
count=$[ $count + 1 ]
|
||||
done
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# trapping the script exit
|
||||
|
||||
trap "echo byebye" EXIT
|
||||
trap "echobyebye" EXIT
|
||||
|
||||
count=1
|
||||
while [ $count -le 5 ]
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# removeing a set trap
|
||||
|
||||
trap "echo byebye" EXIT
|
||||
trap "echobyebye" EXIT
|
||||
|
||||
count=1
|
||||
while [ $count -le 5 ]
|
||||
|
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# 创建数组
|
||||
nums=([2]=2 [0]=0 [1]=1)
|
||||
colors=(red yellow "dark blue")
|
||||
nums=( [ 2 ] = 2 [ 0 ] = 0 [ 1 ] = 1 )
|
||||
colors=( red yellow "dark blue" )
|
||||
|
||||
# 访问数组的单个元素
|
||||
echo ${nums[1]}
|
||||
@ -43,13 +43,13 @@ echo ${#nums[*]}
|
||||
# 3
|
||||
|
||||
# 向数组中添加元素
|
||||
colors=(white "${colors[@]}" green black)
|
||||
colors=( white "${colors[@]}" green black )
|
||||
echo ${colors[@]}
|
||||
# Output:
|
||||
# white red yellow dark blue green black
|
||||
|
||||
# 从数组中删除元素
|
||||
unset nums[0]
|
||||
unset nums[ 0 ]
|
||||
echo ${nums[@]}
|
||||
# Output:
|
||||
# 1 2
|
||||
|
@ -8,7 +8,7 @@ FS=":"
|
||||
}
|
||||
|
||||
{
|
||||
print $1 " " $7
|
||||
print $1 " " $7
|
||||
}
|
||||
|
||||
END {
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#使用内建变量
|
||||
|
||||
# NF 当前记录的字段个数
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#正则表达式
|
||||
|
||||
gawk 'BEGIN{FS=","}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#gawk 自定义函数
|
||||
|
||||
gawk '
|
||||
|
@ -62,5 +62,5 @@ END{ for(c in pop) printf("%15-s%6d\n", c, pop[c]) | "sort -nk 2"; close("sort -
|
||||
#在同一个程序中,如果你写了一个文件,而待会儿想要读取它,那么就需要调用close。
|
||||
#某一时刻,同时处于打开状态的文件或管道数量最大值由实现定义。
|
||||
|
||||
close("sort -nk 2")
|
||||
close ( " sort -nk 2 " )
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#sed编辑器基础
|
||||
|
||||
#替换标记
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# shell wrapper for sed editor script to reverse lines
|
||||
|
||||
sed -n '{
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
#输出末尾10行数据
|
||||
|
||||
sed '{
|
||||
|
@ -7,19 +7,19 @@ function arraydblr {
|
||||
local newarray
|
||||
local elements
|
||||
local i
|
||||
origarry=(`echo "$@"`)
|
||||
newarray=(`echo "$@"`)
|
||||
origarry=( `echo "$@"` )
|
||||
newarray=( `echo "$@"` )
|
||||
elements=$[ $# - 1 ]
|
||||
for (( i=0; i<=$elements; i++ ))
|
||||
for (( i = 0; i <= $elements; i ++ ))
|
||||
{
|
||||
newarray[$i]=$[ ${origarry[$i]} * 2 ]
|
||||
newarray [ $i ] = $[ ${origarry[$i]} * 2 ]
|
||||
}
|
||||
|
||||
echo ${newarray[*]}
|
||||
}
|
||||
|
||||
myarray=(1 2 3 4 5)
|
||||
myarray=( 1 2 3 4 5 )
|
||||
echo "The original array is : ${myarray[*]}"
|
||||
arg1=`echo ${myarray[*]}`
|
||||
result=(`arraydblr $arg1`)
|
||||
result=( `arraydblr $arg1` )
|
||||
echo "The new array is : ${result[*]}"
|
||||
|
@ -1,9 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
# using the echo to return a value
|
||||
|
||||
function db1 {
|
||||
read -p "Enter a value:" value
|
||||
echo $[ $value*2 ]
|
||||
echo $[ $value * 2 ]
|
||||
}
|
||||
|
||||
result=`db1`
|
||||
|
@ -3,7 +3,7 @@
|
||||
# demonstrating the local keyword
|
||||
|
||||
function func1 {
|
||||
local temp=$[ $value +5 ]
|
||||
local temp=$[ $value + 5 ]
|
||||
result=$[ $temp * 2 ]
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ function factorial {
|
||||
then
|
||||
echo 1
|
||||
else
|
||||
local temp=$[ $1 -1 ]
|
||||
local temp=$[ $1 - 1 ]
|
||||
local result=`factorial $temp`
|
||||
echo $[ $result * $1 ]
|
||||
fi
|
||||
|
@ -10,7 +10,7 @@ count=1
|
||||
while [ $count -le 5 ]
|
||||
do
|
||||
func1
|
||||
count=$[ $count+1 ]
|
||||
count=$[ $count + 1 ]
|
||||
done
|
||||
echo "This is the end of the loop"
|
||||
func1
|
||||
|
@ -10,11 +10,11 @@ function testit {
|
||||
echo "The received array is ${thisarray[*]}"
|
||||
|
||||
local newarray
|
||||
newarray=(`echo "$@"`)
|
||||
newarray=( `echo "$@"` )
|
||||
echo "The new array value is : ${newarray[*]}"
|
||||
}
|
||||
|
||||
myarray=(1 2 3 4 5)
|
||||
myarray=( 1 2 3 4 5 )
|
||||
echo "The original array is : ${myarray[*]}"
|
||||
|
||||
#将数组变量当成一个函数参数,函数只会去函数变量第一个值
|
||||
|
@ -5,7 +5,7 @@
|
||||
function addarray {
|
||||
local sum=0
|
||||
local newarray
|
||||
newarray=(`echo "$@"`)
|
||||
newarray=( `echo "$@"` )
|
||||
for value in ${newarray[*]}
|
||||
do
|
||||
sum=$[ $sum + $value ]
|
||||
@ -13,7 +13,7 @@ function addarray {
|
||||
echo $sum
|
||||
}
|
||||
|
||||
myarray=(1 2 3 4 5)
|
||||
myarray=( 1 2 3 4 5 )
|
||||
echo "The original array is : ${myarray[*]}"
|
||||
arg1=`echo ${myarray[*]}`
|
||||
result=`addarray $arg1`
|
||||
|
@ -10,11 +10,13 @@ function multem {
|
||||
echo $[ $1 * $2 ]
|
||||
}
|
||||
|
||||
function divem {
|
||||
if [ $2 -ne 0]
|
||||
then
|
||||
echo $[ $1/$2 ]
|
||||
else
|
||||
echo -1
|
||||
fi
|
||||
function divem
|
||||
|
||||
{
|
||||
if [ $2 -ne 0]
|
||||
then
|
||||
echo $[ $1 / $2 ]
|
||||
else
|
||||
echo -1
|
||||
fi
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# using select in the menu
|
||||
|
||||
function diskspace {
|
||||
@ -19,18 +20,18 @@ function menusage {
|
||||
PS3="Enter option:"
|
||||
select option in "Display disk space" "Display logged on users" "Display memory usage" "Exit program"
|
||||
do
|
||||
case $option in
|
||||
case $option in
|
||||
"Exit program")
|
||||
break;;
|
||||
break ;;
|
||||
"Display disk space")
|
||||
diskspace;;
|
||||
diskspace ;;
|
||||
"Display logged on users")
|
||||
whoseon;;
|
||||
whoseon ;;
|
||||
"Display memory usage")
|
||||
menusage;;
|
||||
menusage ;;
|
||||
*)
|
||||
clear
|
||||
echo "Sorry, wrong selection";;
|
||||
esac
|
||||
echo "Sorry, wrong selection" ;;
|
||||
esac
|
||||
done
|
||||
clear
|
||||
|
@ -32,16 +32,16 @@ do
|
||||
menu
|
||||
case $option in
|
||||
0)
|
||||
break;;
|
||||
break ;;
|
||||
1)
|
||||
diskspace;;
|
||||
diskspace ;;
|
||||
2)
|
||||
whoseon;;
|
||||
whoseon ;;
|
||||
3)
|
||||
menusage;;
|
||||
menusage ;;
|
||||
*)
|
||||
clear
|
||||
echo "Sorry, wrong selection";;
|
||||
echo "Sorry, wrong selection" ;;
|
||||
esac
|
||||
echo -en "\n\n\t\tHit any key to continue"
|
||||
read -n 1 line
|
||||
|
@ -32,13 +32,13 @@ do
|
||||
|
||||
case $selection in
|
||||
1)
|
||||
diskspace;;
|
||||
diskspace ;;
|
||||
2)
|
||||
whoseon;;
|
||||
whoseon ;;
|
||||
3)
|
||||
menusage;;
|
||||
menusage ;;
|
||||
0)
|
||||
break;;
|
||||
break ;;
|
||||
*)
|
||||
dialog --msgbox "Sorry,invalid selection" 10 30
|
||||
esac
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# testing STDERR messages
|
||||
|
||||
echo "This is an error " >&2
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# reading data from a file
|
||||
|
||||
count=1
|
||||
|
@ -1,12 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# simple demonstration of the getopts command
|
||||
|
||||
while getopts :ab:c opt
|
||||
do
|
||||
case "$opt" in
|
||||
a) echo "Found the -a option";;
|
||||
b) echo "Found the -b option, with value $OPTARG";;
|
||||
c) echo "Found the -c option";;
|
||||
*) echo "Unknown option:$opt";;
|
||||
a) echo "Found the -a option" ;;
|
||||
b) echo "Found the -b option, with value $OPTARG" ;;
|
||||
c) echo "Found the -c option" ;;
|
||||
*) echo "Unknown option:$opt" ;;
|
||||
esac
|
||||
done
|
||||
|
@ -1,14 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# processing options and parameters with getopts
|
||||
|
||||
while getopts :ab:cd opt
|
||||
do
|
||||
case "$opt" in
|
||||
a) echo "Found the -a option";;
|
||||
b) echo "Found the -b option,with value $OPTARG";;
|
||||
c) echo "Found the -c option";;
|
||||
d) echo "Found the -d option";;
|
||||
*) echo "Unknown option: $opt";;
|
||||
a) echo "Found the -a option" ;;
|
||||
b) echo "Found the -b option,with value $OPTARG" ;;
|
||||
c) echo "Found the -c option" ;;
|
||||
d) echo "Found the -d option" ;;
|
||||
*) echo "Unknown option: $opt" ;;
|
||||
esac
|
||||
done
|
||||
shift $[ $OPTIND - 1 ]
|
||||
|
@ -1,18 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
#extracting command line options and values with getopt
|
||||
# getopt command is not goot at dealing with space,we can use getopts
|
||||
set -- `getopt -q ab:c "$@"`
|
||||
while [ -n "$1" ]
|
||||
do
|
||||
case "$1" in
|
||||
-a) echo "Found the -a option";;
|
||||
-a) echo "Found the -a option" ;;
|
||||
-b) param="$2"
|
||||
echo "Found the -b option,with parameter value $param"
|
||||
shift;;
|
||||
-c) echo "Found the -c option";;
|
||||
shift ;;
|
||||
-c) echo "Found the -c option" ;;
|
||||
--) shift
|
||||
break;;
|
||||
*) echo "$1 is not an option";;
|
||||
break ;;
|
||||
*) echo "$1 is not an option" ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
@ -21,5 +22,5 @@ count=1
|
||||
for param in "$@"
|
||||
do
|
||||
echo "Parameter #$count: $param"
|
||||
count=$[ $count+1 ]
|
||||
count=$[ $count + 1 ]
|
||||
done
|
||||
|
@ -1,11 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
# shift n 移动变量
|
||||
|
||||
count=1
|
||||
while [ -n "$1" ]
|
||||
do
|
||||
echo "Parameter #$count = $1"
|
||||
count=$[ $count+1 ]
|
||||
count=$[ $count + 1 ]
|
||||
shift
|
||||
done
|
||||
|
||||
|
@ -5,12 +5,12 @@
|
||||
while [ -n "$1" ]
|
||||
do
|
||||
case "$1" in
|
||||
-a) echo "Found the -a option";;
|
||||
-b) echo "Found the -b option";;
|
||||
-c) echo "Found the -c option";;
|
||||
-a) echo "Found the -a option" ;;
|
||||
-b) echo "Found the -b option" ;;
|
||||
-c) echo "Found the -c option" ;;
|
||||
--) shift
|
||||
break;;
|
||||
*) echo "$1 is not an option";;
|
||||
break ;;
|
||||
*) echo "$1 is not an option" ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
# testing lsof with file descriptors
|
||||
|
||||
exec 3>test
|
||||
exec 6>test
|
||||
exec 7<test
|
||||
exec 3> test
|
||||
exec 6> test
|
||||
exec 7< test
|
||||
|
||||
lsof -a -p $$ -d0,1,2,3,6,7
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
tempfile=`mktemp test.XXXXXX`
|
||||
|
||||
exec 3>$tempfile
|
||||
exec 3> $tempfile
|
||||
|
||||
echo "This script writes to temp file $tempfile"
|
||||
|
||||
@ -18,5 +18,5 @@ echo "Done creating temp file. The contents are:"
|
||||
|
||||
cat $tempfile
|
||||
|
||||
rm -f $tempfile 2>/dev/null
|
||||
rm -f $tempfile 2> /dev/null
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user