From 8dff6525fcbcf1a29cb96d53734bab731c9cbbb0 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Thu, 11 Jul 2024 10:11:54 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../check_java_home_and_path_in_batch.sh | 107 +++++++++++++ tools/help_scripts/ip.all | 5 + .../update_to_bisheng_jdk_in_batchs.sh | 140 ++++++++++++++++++ 3 files changed, 252 insertions(+) create mode 100644 tools/help_scripts/check_java_home_and_path_in_batch.sh create mode 100644 tools/help_scripts/ip.all create mode 100644 tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh diff --git a/tools/help_scripts/check_java_home_and_path_in_batch.sh b/tools/help_scripts/check_java_home_and_path_in_batch.sh new file mode 100644 index 0000000..3ff20b6 --- /dev/null +++ b/tools/help_scripts/check_java_home_and_path_in_batch.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +# 安装的目标位置,当前最终安装在/opt/software/bisheng-jdk1.8.0_402 +TARGET_DIR=/opt/software/bisheng-jdk1.8.0_402 +# 哪些服务器需要安装 每行一个服务器 格式:ip password 。其中password可以不写 默认为DEFAULT_PASSWORD +IP_FILE=ip.all +# 服务器的登陆用户 +USER=root +# 默认密码,在IP_FILE未进行配置的服务器使用的密码 +DEFAULT_PASSWORD="Huawei123" + +declare -A ip_arr +declare -A passwd_arr + +function initialize_arr() { + local index=0 + # + while read line || [[ -n ${line} ]] + do + local ip=`echo "${line}"|awk '{print $1}'` + if [[ -n $ip ]];then + continue + fi + local password=`echo "${line}"|awk '{print $2}'` + # + if [[ -z $password ]];then + password=$DEFAULT_PASSWORD + fi + ip_arr[$index]=$ip + passwd_arr[$index]=$password + index=`expr $index + 1` + done < ${IP_FILE} +} + +function connect_host_and_check_bisheng_jdk() { + local ip=$1 + local passwd=$2 +/usr/bin/expect > /dev/null << EOF +set timeout 10 +send_user "$USER@$ip:create dir" +spawn ssh $USER@Sip +expect { + "*yes/no" {send "yes\r";exp_continue} + "*password" {send "$passwd\r";exp_continue} + "*Password" {send "$passwd\r";exp_continue} + "Enter passphrase for key*" {send "$passwd\r";exp_continue} + "Permission denied, please try again" {send_user "Permission denied to login user:$USER"; exit 1;} + "Last login:" {send_user "success to login"} + timeout {send_user "time out to login user:$USER"; exit 2} +} + +expect -re "$|#" { send "ls $TARGET_DIR\r"} +expect { + "No such file" {send_user "success to update JAVA_HOME";exit 3} + "$TARGET_DIR" {send_user "success to copy bisheng jdk to server";} + timeout {send_user "time out to ls"; exit 3} +} + +expect -re "$|#" { send "echo \$JAVA_HOME\r"} +expect { + "$TARGET_DIR" {send_user "success to update JAVA_HOME";} + timeout {send_user "time out to echo JAVA_HOME"; exit 4} +} + +expect -re "$|#" { send "which java\r"} +expect { + "$TARGET_DIR" {send_user "success to login";} + timeout {send_user "time out to which java"; exit 5} +} +expect -re "$|#" { send "logout\r"} +expect eof +EOF +} + +function print_result() { + local index=$1 + local ret=$2 + if [[ $ret -eq 0 ]];then + echo -e "\033[32m 服务器${ip_arr[$index]} 安装成功,且修改的环境变量(JAVA_HOME)和PATH在用户${USER}生效。\033[0m" + elif [[ $ret -eq 1 ]];then + echo -e "\033[31m 服务器${ip_arr[$index]} 密码错误。\033[0m" + elif [[ $ret -eq 2 ]];then + echo -e "\033[31m 服务器${ip_arr[$index]} 登陆超时。可能原因:服务器地址不正确或者登陆返回不包含Last login或者缺少命令 \033[0m" + elif [[ $ret -eq 3 ]];then + echo -e "\033[31m 服务器${ip_arr[$index]} 不存在文件夹$TARGET_DIR。 \033[0m" + elif [[ $ret -eq 4 ]];then + echo -e "\033[31m 服务器${ip_arr[$index]} 用户${USER}的环境变量JAVA_HOME不是$TARGET_DIR。 \033[0m" + else + echo -e "\033[31m 服务器${ip_arr[$index]} 直接使用java命令不是${TARGET_DIR}/bin/java。\033[0m" + fi +} + +function check_all_host() { + for ((i=0;i<${#ip_arr[@]};i++)) + do + connect_host_and_check_bisheng_jdk "${ip_arr[$i]}" ${passwd_arr[$i]} + print_result $i $? + done +} + + +function main() { + initialize_arr + check_all_host +} + +main \ No newline at end of file diff --git a/tools/help_scripts/ip.all b/tools/help_scripts/ip.all new file mode 100644 index 0000000..c50cd5a --- /dev/null +++ b/tools/help_scripts/ip.all @@ -0,0 +1,5 @@ +# 本行为注释使用时删除, 每行包含两个字段,分隔符为空格,第一个字段为密码,第二个字段为密码(可不填),不填密码时使用脚本中的默认密码 +192.168.0.1 admin123 +192.168.0.2 +192.168.0.3 admin123 +192.168.0.4 \ No newline at end of file diff --git a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh new file mode 100644 index 0000000..8b0287c --- /dev/null +++ b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh @@ -0,0 +1,140 @@ +#!/bin/bash + +# 存放bishengJDK的目录 +BISHENG_TAR_DIR=/home/zpp +# bishengJDK的文件名称 +BISHENG_JDK_TAR=bisheng-jdk-8u402-linux-aarch64.tar.gz +# bishengJDK解压后的文件夹名称 +BISHENG_DIR=bisheng-jdk1.8.0_402 +# 安装的目标位置,当前最终安装在/opt/software/bisheng-jdk1.8.0_402 +TARGET_DIR=/opt/software +# 哪些服务器需要安装 每行一个服务器 格式:ip password 。其中password可以不写 默认为DEFAULT_PASSWORD +IP_FILE=/home/zpp/ip.all +# 服务器的登陆用户 +USER=root +# 默认密码,在IP_FILE未进行配置的服务器使用的密码 +DEFAULT_PASSWORD="Huawei123" +# 并行度,同时进行安装的服务器个数 +PARALLEL=10 + +# 在/etc/profile 中追加的内容 +ADD_JAVA_HOME="export JAVA_HOME=${TARGET_DIR}/${BISHENG_DIR}" +ADD_PATH="export PATH=\${JAVA_HOME}/bin:\${PATH}" + +declare -A ip_arr +declare -A passwd_arr + +function initialize_arr() { + local index=0 + # + while read line || [[ -n ${line} ]] + do + local ip=`echo "${line}"|awk '{print $1}'` + if [[ -n $ip ]];then + continue + fi + local password=`echo "${line}"|awk '{print $2}'` + # + if [[ -z $password ]];then + password=$DEFAULT_PASSWORD + fi + ip_arr[$index]=$ip + passwd_arr[$index]=$password + index=`expr $index + 1` + done < ${IP_FILE} +} + +function connect_host_and_update_to_bisheng_jdk() { + local ip=$1 + local passwd=$2 +/usr/bin/expect << EOF +set timeout 10 +send_user "$USER@$ip:create dir" +spawn ssh $USER@Sip +expect { + "*yes/no" {send "yes\r";exp_continue} + "*password" {send "$passwd\r";exp_continue} + "*Password" {send "$passwd\r";exp_continue} + "Enter passphrase for key*" {send "$passwd\r";exp_continue} + "Permission denied, please try again" {send_user "Permission denied to login user:$USER"; exit 1;} + "Last login:" {send_user "success to login"} + timeout {send_user "time out to login user:$USER"; exit 2} +} +expect -re "$|#" { send "mkdir -p $TARGET_DIR\r"} +expect -re "$|#" { send "logout\r"} + +expect -re "$|#" +spawn scp -r $BISHENG_TAR_DIR/$BISHENG_JDK_TAR $USER@Sip:$TARGET_DIR +expect{ + "*yes/no" {send "yes\r";exp_continue} + "*password" {send "$passwd\r";} + "*Password" {send "$passwd\r";} + "Enter passphrase for key*" {send "$passwd\r";} + -re "$|#" {send_user "success to copy file\n"} +} + +expect -re "$|#" +spawn ssh $USER@Sip +expect { + "*yes/no" {send "yes\r";exp_continue} + "*password" {send "$passwd\r";} + "*Password" {send "$passwd\r";} + "Enter passphrase for key*" {send "$passwd\r";} + "Last login:" {send_user "success to login"} +} +expect -re "$|#" { send "tar --no-same-owner -xzf $TARGET_DIR/$BISHENG_JDK_TAR -C ${TARGET_DIR}\r"} +expect -re "$|#" { send "rm -rf $TARGET_DIR/$BISHENG_JDK_TAR\r"} +expect -re "$|#" { send "chmod -R 755 $TARGET_DIR\r"} +expect -re "$|#" { send "echo $ADD_JAVA_HOME >>/etc/profile\r"} +expect -re "$|#" { send "echo '$ADD_PATH' >>/etc/profile\r"} +expect -re "$|#" { send "logout\r"} +expect eof +EOF +} + +function print_result() { + local index=$1 + local ret=$2 + if [[ $ret -eq 0 ]];then + echo -e "\033[32m 服务器${ip_arr[$index]}安装成功。安装位置为$TARGET_DIR,并在/etc/profile文件中追加了以下配置:\n ${ADD_JAVA_HOME}\n${ADD_PATH} \033[0m" + elif [[ $ret -eq 1 ]];then + echo -e "\033[31m 服务器${ip_arr[$index]} 密码错误。\033[0m" + else + echo -e "\033[31m 服务器${ip_arr[$index]} 未安装成功。可能原因:服务器地址不正确或者登陆返回不包含Last login或者缺少命令 \033[0m" + fi +} + +function update_all_host() { + local arr_length=${#ip_arr[@]} + if [ $arr_length -gt $PARALLEL ];then + for ((i=0;i<${PARALLEL};i++)) + do + { + for ((j=i;j<${arr_length};j=j+$PARALLEL)) + do + connect_host_and_update_to_bisheng_jdk "${ip_arr[$j]}" ${passwd_arr[$j]} + print_result $j $? + done + } & + done + wait + else + for ((i=0;i<${arr_length};i++)) + do + { + connect_host_and_update_to_bisheng_jdk "${ip_arr[$i]}" ${passwd_arr[$i]} + print_result $i $? + } & + done + wait + fi + +} + + +function main() { + initialize_arr + update_all_host +} + +main \ No newline at end of file -- Gitee From 890b22ae33f6161c8f21fe0d03ab4aede1560196 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Thu, 11 Jul 2024 10:16:42 +0800 Subject: [PATCH 02/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/check_java_home_and_path_in_batch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/help_scripts/check_java_home_and_path_in_batch.sh b/tools/help_scripts/check_java_home_and_path_in_batch.sh index 3ff20b6..0cc7f69 100644 --- a/tools/help_scripts/check_java_home_and_path_in_batch.sh +++ b/tools/help_scripts/check_java_home_and_path_in_batch.sh @@ -49,7 +49,7 @@ expect { timeout {send_user "time out to login user:$USER"; exit 2} } -expect -re "$|#" { send "ls $TARGET_DIR\r"} +expect -re "$|#" { send "ls -l $TARGET_DIR\r"} expect { "No such file" {send_user "success to update JAVA_HOME";exit 3} "$TARGET_DIR" {send_user "success to copy bisheng jdk to server";} -- Gitee From fc19519e8cc1be3ad93af7dd914b91a4e64ecbf0 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Thu, 11 Jul 2024 14:39:28 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../check_java_home_and_path_in_batch.sh | 40 +++++++++++-------- .../update_to_bisheng_jdk_in_batchs.sh | 25 +++++++----- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/tools/help_scripts/check_java_home_and_path_in_batch.sh b/tools/help_scripts/check_java_home_and_path_in_batch.sh index 0cc7f69..1d98275 100644 --- a/tools/help_scripts/check_java_home_and_path_in_batch.sh +++ b/tools/help_scripts/check_java_home_and_path_in_batch.sh @@ -1,7 +1,11 @@ #!/bin/bash +# 检查bishengJDK安装的三个方面 +# 1. 检查安装路径是否存在 +# 2. 检查JAVA_HOME是否和安装路径一致 +# 3. 检查java命令的全路径形式包含安装路径 -# 安装的目标位置,当前最终安装在/opt/software/bisheng-jdk1.8.0_402 -TARGET_DIR=/opt/software/bisheng-jdk1.8.0_402 +# 安装的目标位置,当前最终安装在/opt/software/bisheng-jdk1.8.0_412 +TARGET_DIR=/opt/software/bisheng-jdk1.8.0_412 # 哪些服务器需要安装 每行一个服务器 格式:ip password 。其中password可以不写 默认为DEFAULT_PASSWORD IP_FILE=ip.all # 服务器的登陆用户 @@ -18,7 +22,7 @@ function initialize_arr() { while read line || [[ -n ${line} ]] do local ip=`echo "${line}"|awk '{print $1}'` - if [[ -n $ip ]];then + if [[ -z $ip ]];then continue fi local password=`echo "${line}"|awk '{print $2}'` @@ -38,33 +42,35 @@ function connect_host_and_check_bisheng_jdk() { /usr/bin/expect > /dev/null << EOF set timeout 10 send_user "$USER@$ip:create dir" -spawn ssh $USER@Sip +spawn ssh $USER@$ip expect { "*yes/no" {send "yes\r";exp_continue} + "Permission denied, please try again" {send_user "Permission denied to login user:$USER"; exit 1;} "*password" {send "$passwd\r";exp_continue} "*Password" {send "$passwd\r";exp_continue} "Enter passphrase for key*" {send "$passwd\r";exp_continue} - "Permission denied, please try again" {send_user "Permission denied to login user:$USER"; exit 1;} - "Last login:" {send_user "success to login"} - timeout {send_user "time out to login user:$USER"; exit 2} + "Last login:" {send_user "success to login\n"} + timeout {send_user "time out to login user:$USER\n"; exit 2} } -expect -re "$|#" { send "ls -l $TARGET_DIR\r"} +expect -re "$|#" { send "if \[ -d $TARGET_DIR \];then echo \"True\"; else echo \"False\";fi\r"} expect { - "No such file" {send_user "success to update JAVA_HOME";exit 3} - "$TARGET_DIR" {send_user "success to copy bisheng jdk to server";} - timeout {send_user "time out to ls"; exit 3} + "True" {send_user "success to copy bisheng jdk to server";} + "False" {send_user "failed to copy bisheng jdk to server";exit 3} + timeout {send_user "time out to -d"; exit 3} } -expect -re "$|#" { send "echo \$JAVA_HOME\r"} +expect -re "$|#" { send "env|grep JAVA_HOME"} expect { "$TARGET_DIR" {send_user "success to update JAVA_HOME";} - timeout {send_user "time out to echo JAVA_HOME"; exit 4} + -re "$|#" {send_user "failed to update JAVA_HOME"; exit 4} + timeout {send_user "time out to env JAVA_HOME"; exit 4} } expect -re "$|#" { send "which java\r"} expect { - "$TARGET_DIR" {send_user "success to login";} + "$TARGET_DIR" {send_user "success to update PATH";} + -re "$|#" {send_user "failed to update PATH"; exit 5} timeout {send_user "time out to which java"; exit 5} } expect -re "$|#" { send "logout\r"} @@ -82,11 +88,11 @@ function print_result() { elif [[ $ret -eq 2 ]];then echo -e "\033[31m 服务器${ip_arr[$index]} 登陆超时。可能原因:服务器地址不正确或者登陆返回不包含Last login或者缺少命令 \033[0m" elif [[ $ret -eq 3 ]];then - echo -e "\033[31m 服务器${ip_arr[$index]} 不存在文件夹$TARGET_DIR。 \033[0m" + echo -e "\033[31m 服务器${ip_arr[$index]} 中 $TARGET_DIR 文件夹不存在。 \033[0m" elif [[ $ret -eq 4 ]];then - echo -e "\033[31m 服务器${ip_arr[$index]} 用户${USER}的环境变量JAVA_HOME不是$TARGET_DIR。 \033[0m" + echo -e "\033[31m 服务器${ip_arr[$index]} 用户${USER}的JAVA_HOME环境变量不是$TARGET_DIR。 \033[0m" else - echo -e "\033[31m 服务器${ip_arr[$index]} 直接使用java命令不是${TARGET_DIR}/bin/java。\033[0m" + echo -e "\033[31m 服务器${ip_arr[$index]} 直接使用的java命令不是${TARGET_DIR}/bin/java。\033[0m" fi } diff --git a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh index 8b0287c..e7be67f 100644 --- a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh +++ b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh @@ -1,15 +1,18 @@ #!/bin/bash +# 该脚本做两件事 +# 1. 复制BISHENG_TAR_DIR下的文件BISHENG_JDK_TAR到指定服务器的TARGET_DIR目录下,并解压 +# 2. 在/etc/profile中追加 export JAVA_HOME=${TARGET_DIR}/${BISHENG_DIR} 和export PATH=\${JAVA_HOME}/bin:\${PATH} # 存放bishengJDK的目录 BISHENG_TAR_DIR=/home/zpp # bishengJDK的文件名称 -BISHENG_JDK_TAR=bisheng-jdk-8u402-linux-aarch64.tar.gz +BISHENG_JDK_TAR=bisheng-jdk-8u412-linux-aarch64.tar.gz # bishengJDK解压后的文件夹名称 -BISHENG_DIR=bisheng-jdk1.8.0_402 -# 安装的目标位置,当前最终安装在/opt/software/bisheng-jdk1.8.0_402 +BISHENG_DIR=bisheng-jdk1.8.0_412 +# 安装的目标位置,当前最终安装在/opt/software/bisheng-jdk1.8.0_412 TARGET_DIR=/opt/software # 哪些服务器需要安装 每行一个服务器 格式:ip password 。其中password可以不写 默认为DEFAULT_PASSWORD -IP_FILE=/home/zpp/ip.all +IP_FILE=ip.all # 服务器的登陆用户 USER=root # 默认密码,在IP_FILE未进行配置的服务器使用的密码 @@ -19,7 +22,7 @@ PARALLEL=10 # 在/etc/profile 中追加的内容 ADD_JAVA_HOME="export JAVA_HOME=${TARGET_DIR}/${BISHENG_DIR}" -ADD_PATH="export PATH=\${JAVA_HOME}/bin:\${PATH}" +ADD_PATH='export PATH=\${JAVA_HOME}/bin:\${PATH}' declare -A ip_arr declare -A passwd_arr @@ -30,7 +33,7 @@ function initialize_arr() { while read line || [[ -n ${line} ]] do local ip=`echo "${line}"|awk '{print $1}'` - if [[ -n $ip ]];then + if [[ -z $ip ]];then continue fi local password=`echo "${line}"|awk '{print $2}'` @@ -50,13 +53,13 @@ function connect_host_and_update_to_bisheng_jdk() { /usr/bin/expect << EOF set timeout 10 send_user "$USER@$ip:create dir" -spawn ssh $USER@Sip +spawn ssh $USER@$ip expect { "*yes/no" {send "yes\r";exp_continue} + "Permission denied, please try again" {send_user "Permission denied to login user:$USER"; exit 1;} "*password" {send "$passwd\r";exp_continue} "*Password" {send "$passwd\r";exp_continue} "Enter passphrase for key*" {send "$passwd\r";exp_continue} - "Permission denied, please try again" {send_user "Permission denied to login user:$USER"; exit 1;} "Last login:" {send_user "success to login"} timeout {send_user "time out to login user:$USER"; exit 2} } @@ -64,8 +67,8 @@ expect -re "$|#" { send "mkdir -p $TARGET_DIR\r"} expect -re "$|#" { send "logout\r"} expect -re "$|#" -spawn scp -r $BISHENG_TAR_DIR/$BISHENG_JDK_TAR $USER@Sip:$TARGET_DIR -expect{ +spawn scp -r $BISHENG_TAR_DIR/$BISHENG_JDK_TAR $USER@$ip:$TARGET_DIR +expect { "*yes/no" {send "yes\r";exp_continue} "*password" {send "$passwd\r";} "*Password" {send "$passwd\r";} @@ -74,7 +77,7 @@ expect{ } expect -re "$|#" -spawn ssh $USER@Sip +spawn ssh $USER@$ip expect { "*yes/no" {send "yes\r";exp_continue} "*password" {send "$passwd\r";} -- Gitee From 40f261a470f21b0e2cb9deb970161fab2361b734 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Thu, 11 Jul 2024 14:52:03 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../check_java_home_and_path_in_batch.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/help_scripts/check_java_home_and_path_in_batch.sh b/tools/help_scripts/check_java_home_and_path_in_batch.sh index 1d98275..5bf3722 100644 --- a/tools/help_scripts/check_java_home_and_path_in_batch.sh +++ b/tools/help_scripts/check_java_home_and_path_in_batch.sh @@ -4,9 +4,9 @@ # 2. 检查JAVA_HOME是否和安装路径一致 # 3. 检查java命令的全路径形式包含安装路径 -# 安装的目标位置,当前最终安装在/opt/software/bisheng-jdk1.8.0_412 -TARGET_DIR=/opt/software/bisheng-jdk1.8.0_412 -# 哪些服务器需要安装 每行一个服务器 格式:ip password 。其中password可以不写 默认为DEFAULT_PASSWORD +# 安装的目标位置,即JAVA_HOME +JAVA_HOME_VALUE=/opt/software/bisheng-jdk1.8.0_412 +# 哪些服务器需要检查 每行一个服务器 格式:ip password 。其中password可以不写 默认为DEFAULT_PASSWORD IP_FILE=ip.all # 服务器的登陆用户 USER=root @@ -53,7 +53,7 @@ expect { timeout {send_user "time out to login user:$USER\n"; exit 2} } -expect -re "$|#" { send "if \[ -d $TARGET_DIR \];then echo \"True\"; else echo \"False\";fi\r"} +expect -re "$|#" { send "if \[ -d $JAVA_HOME_VALUE \];then echo \"True\"; else echo \"False\";fi\r"} expect { "True" {send_user "success to copy bisheng jdk to server";} "False" {send_user "failed to copy bisheng jdk to server";exit 3} @@ -62,14 +62,14 @@ expect { expect -re "$|#" { send "env|grep JAVA_HOME"} expect { - "$TARGET_DIR" {send_user "success to update JAVA_HOME";} + "$JAVA_HOME_VALUE" {send_user "success to update JAVA_HOME";} -re "$|#" {send_user "failed to update JAVA_HOME"; exit 4} timeout {send_user "time out to env JAVA_HOME"; exit 4} } expect -re "$|#" { send "which java\r"} expect { - "$TARGET_DIR" {send_user "success to update PATH";} + "$JAVA_HOME_VALUE" {send_user "success to update PATH";} -re "$|#" {send_user "failed to update PATH"; exit 5} timeout {send_user "time out to which java"; exit 5} } @@ -88,11 +88,11 @@ function print_result() { elif [[ $ret -eq 2 ]];then echo -e "\033[31m 服务器${ip_arr[$index]} 登陆超时。可能原因:服务器地址不正确或者登陆返回不包含Last login或者缺少命令 \033[0m" elif [[ $ret -eq 3 ]];then - echo -e "\033[31m 服务器${ip_arr[$index]} 中 $TARGET_DIR 文件夹不存在。 \033[0m" + echo -e "\033[31m 服务器${ip_arr[$index]} 中 $JAVA_HOME_VALUE 文件夹不存在。 \033[0m" elif [[ $ret -eq 4 ]];then - echo -e "\033[31m 服务器${ip_arr[$index]} 用户${USER}的JAVA_HOME环境变量不是$TARGET_DIR。 \033[0m" + echo -e "\033[31m 服务器${ip_arr[$index]} 用户${USER}的JAVA_HOME环境变量不是$JAVA_HOME_VALUE。 \033[0m" else - echo -e "\033[31m 服务器${ip_arr[$index]} 直接使用的java命令不是${TARGET_DIR}/bin/java。\033[0m" + echo -e "\033[31m 服务器${ip_arr[$index]} 直接使用的java命令不是${JAVA_HOME_VALUE}/bin/java。\033[0m" fi } -- Gitee From 2d086cf1a0bda784ea99aa099fa5bb3c047db799 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Fri, 12 Jul 2024 13:25:43 +0800 Subject: [PATCH 05/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh index e7be67f..159fc4b 100644 --- a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh +++ b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh @@ -73,7 +73,7 @@ expect { "*password" {send "$passwd\r";} "*Password" {send "$passwd\r";} "Enter passphrase for key*" {send "$passwd\r";} - -re "$|#" {send_user "success to copy file\n"} + timeout {send_user "success to copy file\n"} } expect -re "$|#" -- Gitee From 96d293dfd5634c5ccb8726ac90d918c556213985 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Fri, 12 Jul 2024 13:34:57 +0800 Subject: [PATCH 06/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh index 159fc4b..85f1636 100644 --- a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh +++ b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh @@ -73,7 +73,8 @@ expect { "*password" {send "$passwd\r";} "*Password" {send "$passwd\r";} "Enter passphrase for key*" {send "$passwd\r";} - timeout {send_user "success to copy file\n"} + "Authorized users" { send_user "success to copy file\n"} + timeout {exit 2} } expect -re "$|#" -- Gitee From 7080b79b73fcf8c0608fa4bfb86416ae4530ea0b Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Fri, 12 Jul 2024 13:36:21 +0800 Subject: [PATCH 07/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh index 85f1636..be526aa 100644 --- a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh +++ b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh @@ -73,7 +73,7 @@ expect { "*password" {send "$passwd\r";} "*Password" {send "$passwd\r";} "Enter passphrase for key*" {send "$passwd\r";} - "Authorized users" { send_user "success to copy file\n"} + "$BISHENG_JDK_TAR" { send_user "success to copy file\n"} timeout {exit 2} } -- Gitee From 6e1f7b18935f9e81b218f91ab103006450a1b81a Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Fri, 12 Jul 2024 14:12:06 +0800 Subject: [PATCH 08/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh index be526aa..d9f1d48 100644 --- a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh +++ b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh @@ -66,17 +66,20 @@ expect { expect -re "$|#" { send "mkdir -p $TARGET_DIR\r"} expect -re "$|#" { send "logout\r"} +set timeout 120 expect -re "$|#" spawn scp -r $BISHENG_TAR_DIR/$BISHENG_JDK_TAR $USER@$ip:$TARGET_DIR expect { "*yes/no" {send "yes\r";exp_continue} - "*password" {send "$passwd\r";} - "*Password" {send "$passwd\r";} - "Enter passphrase for key*" {send "$passwd\r";} - "$BISHENG_JDK_TAR" { send_user "success to copy file\n"} + "*password" {send "$passwd\r";exp_continue} + "*Password" {send "$passwd\r";exp_continue} + "Enter passphrase for key*" {send "$passwd\r";exp_continue} + "100%" { send_user "success to copy file\n"} timeout {exit 2} } +set timeout 10 + expect -re "$|#" spawn ssh $USER@$ip expect { -- Gitee From caa0ea663db10ea1f820991dca29e0c710a336c1 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Mon, 15 Jul 2024 10:59:08 +0800 Subject: [PATCH 09/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh index d9f1d48..ceb3df5 100644 --- a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh +++ b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh @@ -84,10 +84,12 @@ expect -re "$|#" spawn ssh $USER@$ip expect { "*yes/no" {send "yes\r";exp_continue} - "*password" {send "$passwd\r";} - "*Password" {send "$passwd\r";} - "Enter passphrase for key*" {send "$passwd\r";} + "Permission denied, please try again" {send_user "Permission denied to login user:$USER"; exit 1;} + "*password" {send "$passwd\r";exp_continue} + "*Password" {send "$passwd\r";exp_continue} + "Enter passphrase for key*" {send "$passwd\r";exp_continue} "Last login:" {send_user "success to login"} + timeout {send_user "time out to login user:$USER"; exit 2} } expect -re "$|#" { send "tar --no-same-owner -xzf $TARGET_DIR/$BISHENG_JDK_TAR -C ${TARGET_DIR}\r"} expect -re "$|#" { send "rm -rf $TARGET_DIR/$BISHENG_JDK_TAR\r"} -- Gitee From 8495a99629f3ca2a6726ee1d72beeda42b14cf23 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Mon, 15 Jul 2024 13:13:24 +0800 Subject: [PATCH 10/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/unpack_and_modify.sh | 21 +++++++++++++++++ .../update_to_bisheng_jdk_in_batchs.sh | 23 +++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 tools/help_scripts/unpack_and_modify.sh diff --git a/tools/help_scripts/unpack_and_modify.sh b/tools/help_scripts/unpack_and_modify.sh new file mode 100644 index 0000000..9e9949a --- /dev/null +++ b/tools/help_scripts/unpack_and_modify.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e +# bishengJDK的文件名称 +BISHENG_JDK_TAR=$1 +# bishengJDK解压后的文件夹名称 +BISHENG_DIR=$2 +# 安装的目标位置,当前最终安装在/opt/software/bisheng-jdk1.8.0_412 +TARGET_DIR=$3 + +# 在/etc/profile 中追加的内容 +ADD_JAVA_HOME="export JAVA_HOME=${TARGET_DIR}/${BISHENG_DIR}" + +tar --no-same-owner -xzf $TARGET_DIR/$BISHENG_JDK_TAR -C ${TARGET_DIR} +chmod -R 755 $TARGET_DIR + +echo $ADD_JAVA_HOME >>/etc/profile + +echo 'export PATH=\${JAVA_HOME}/bin:\${PATH}' >>/etc/profile + +echo "success" \ No newline at end of file diff --git a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh index ceb3df5..59d7509 100644 --- a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh +++ b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh @@ -78,7 +78,18 @@ expect { timeout {exit 2} } -set timeout 10 +set timeout 20 + +expect -re "$|#" +spawn scp -r unpack_and_modify.sh $USER@$ip:$TARGET_DIR +expect { + "*yes/no" {send "yes\r";exp_continue} + "*password" {send "$passwd\r";exp_continue} + "*Password" {send "$passwd\r";exp_continue} + "Enter passphrase for key*" {send "$passwd\r";exp_continue} + "100%" { send_user "success to copy unpack_and_modify file\n"} + timeout {exit 2} +} expect -re "$|#" spawn ssh $USER@$ip @@ -91,11 +102,13 @@ expect { "Last login:" {send_user "success to login"} timeout {send_user "time out to login user:$USER"; exit 2} } -expect -re "$|#" { send "tar --no-same-owner -xzf $TARGET_DIR/$BISHENG_JDK_TAR -C ${TARGET_DIR}\r"} +expect -re "$|#" { send "bash ${TARGET_DIR}/unpack_and_modify.sh ${BISHENG_JDK_TAR} ${BISHENG_DIR} ${TARGET_DIR}\r"} +expect { + "success" {send_user "success to unpack_and_modify"} + timeout {send_user "time out to login user:$USER"; exit 2} +} expect -re "$|#" { send "rm -rf $TARGET_DIR/$BISHENG_JDK_TAR\r"} -expect -re "$|#" { send "chmod -R 755 $TARGET_DIR\r"} -expect -re "$|#" { send "echo $ADD_JAVA_HOME >>/etc/profile\r"} -expect -re "$|#" { send "echo '$ADD_PATH' >>/etc/profile\r"} +expect -re "$|#" { send "rm -rf $TARGET_DIR/unpack_and_modify.sh\r"} expect -re "$|#" { send "logout\r"} expect eof EOF -- Gitee From 98ba46acbd133a75e0717cf39df0a3e75f75e25b Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Mon, 15 Jul 2024 13:20:27 +0800 Subject: [PATCH 11/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/unpack_and_modify.sh | 2 +- tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/help_scripts/unpack_and_modify.sh b/tools/help_scripts/unpack_and_modify.sh index 9e9949a..d9619a8 100644 --- a/tools/help_scripts/unpack_and_modify.sh +++ b/tools/help_scripts/unpack_and_modify.sh @@ -16,6 +16,6 @@ chmod -R 755 $TARGET_DIR echo $ADD_JAVA_HOME >>/etc/profile -echo 'export PATH=\${JAVA_HOME}/bin:\${PATH}' >>/etc/profile +echo 'export PATH=${JAVA_HOME}/bin:${PATH}' >>/etc/profile echo "success" \ No newline at end of file diff --git a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh index 59d7509..1b889e5 100644 --- a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh +++ b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh @@ -105,7 +105,7 @@ expect { expect -re "$|#" { send "bash ${TARGET_DIR}/unpack_and_modify.sh ${BISHENG_JDK_TAR} ${BISHENG_DIR} ${TARGET_DIR}\r"} expect { "success" {send_user "success to unpack_and_modify"} - timeout {send_user "time out to login user:$USER"; exit 2} + timeout {send_user "time out to unpack_and_modify:$USER"; exit 2} } expect -re "$|#" { send "rm -rf $TARGET_DIR/$BISHENG_JDK_TAR\r"} expect -re "$|#" { send "rm -rf $TARGET_DIR/unpack_and_modify.sh\r"} -- Gitee From c91424a9a1623ed5f6efde7aa3393cfe838fa689 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Mon, 15 Jul 2024 13:26:12 +0800 Subject: [PATCH 12/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh index 1b889e5..e0460d9 100644 --- a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh +++ b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh @@ -91,6 +91,7 @@ expect { timeout {exit 2} } +set timeout 10 expect -re "$|#" spawn ssh $USER@$ip expect { -- Gitee From f50b98213110052b495db6ed457bfac01e131bfc Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Mon, 15 Jul 2024 15:28:45 +0800 Subject: [PATCH 13/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/check_java_home_and_path_in_batch.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/help_scripts/check_java_home_and_path_in_batch.sh b/tools/help_scripts/check_java_home_and_path_in_batch.sh index 5bf3722..87bb819 100644 --- a/tools/help_scripts/check_java_home_and_path_in_batch.sh +++ b/tools/help_scripts/check_java_home_and_path_in_batch.sh @@ -39,7 +39,7 @@ function initialize_arr() { function connect_host_and_check_bisheng_jdk() { local ip=$1 local passwd=$2 -/usr/bin/expect > /dev/null << EOF +/usr/bin/expect << EOF set timeout 10 send_user "$USER@$ip:create dir" spawn ssh $USER@$ip @@ -63,14 +63,12 @@ expect { expect -re "$|#" { send "env|grep JAVA_HOME"} expect { "$JAVA_HOME_VALUE" {send_user "success to update JAVA_HOME";} - -re "$|#" {send_user "failed to update JAVA_HOME"; exit 4} timeout {send_user "time out to env JAVA_HOME"; exit 4} } expect -re "$|#" { send "which java\r"} expect { "$JAVA_HOME_VALUE" {send_user "success to update PATH";} - -re "$|#" {send_user "failed to update PATH"; exit 5} timeout {send_user "time out to which java"; exit 5} } expect -re "$|#" { send "logout\r"} -- Gitee From f53ff550259e1cf91b50ca461d5cd4e6a8d88ad6 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Mon, 15 Jul 2024 15:33:20 +0800 Subject: [PATCH 14/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/check_java_home_and_path_in_batch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/help_scripts/check_java_home_and_path_in_batch.sh b/tools/help_scripts/check_java_home_and_path_in_batch.sh index 87bb819..b8b72c2 100644 --- a/tools/help_scripts/check_java_home_and_path_in_batch.sh +++ b/tools/help_scripts/check_java_home_and_path_in_batch.sh @@ -60,7 +60,7 @@ expect { timeout {send_user "time out to -d"; exit 3} } -expect -re "$|#" { send "env|grep JAVA_HOME"} +expect -re "$|#" { send "env|grep JAVA_HOME\r"} expect { "$JAVA_HOME_VALUE" {send_user "success to update JAVA_HOME";} timeout {send_user "time out to env JAVA_HOME"; exit 4} -- Gitee From 17f82ab8d8923a807f3bc8d3a7f8f49379cd35e4 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Mon, 15 Jul 2024 15:35:24 +0800 Subject: [PATCH 15/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../check_java_home_and_path_in_batch.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/help_scripts/check_java_home_and_path_in_batch.sh b/tools/help_scripts/check_java_home_and_path_in_batch.sh index b8b72c2..a55247e 100644 --- a/tools/help_scripts/check_java_home_and_path_in_batch.sh +++ b/tools/help_scripts/check_java_home_and_path_in_batch.sh @@ -55,21 +55,21 @@ expect { expect -re "$|#" { send "if \[ -d $JAVA_HOME_VALUE \];then echo \"True\"; else echo \"False\";fi\r"} expect { - "True" {send_user "success to copy bisheng jdk to server";} - "False" {send_user "failed to copy bisheng jdk to server";exit 3} + "True" {send_user "success to copy bisheng jdk to server\n";} + "False" {send_user "failed to copy bisheng jdk to server\n";exit 3} timeout {send_user "time out to -d"; exit 3} } expect -re "$|#" { send "env|grep JAVA_HOME\r"} expect { - "$JAVA_HOME_VALUE" {send_user "success to update JAVA_HOME";} - timeout {send_user "time out to env JAVA_HOME"; exit 4} + "$JAVA_HOME_VALUE" {send_user "success to update JAVA_HOME\n";} + timeout {send_user "time out to env JAVA_HOME\n"; exit 4} } expect -re "$|#" { send "which java\r"} expect { - "$JAVA_HOME_VALUE" {send_user "success to update PATH";} - timeout {send_user "time out to which java"; exit 5} + "$JAVA_HOME_VALUE" {send_user "success to update PATH\n";} + timeout {send_user "time out to which java\n"; exit 5} } expect -re "$|#" { send "logout\r"} expect eof -- Gitee From 84f89a3bb25149dddf910d7183f76e88733d9624 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Mon, 15 Jul 2024 15:49:19 +0800 Subject: [PATCH 16/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/check_java_home_and_path_in_batch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/help_scripts/check_java_home_and_path_in_batch.sh b/tools/help_scripts/check_java_home_and_path_in_batch.sh index a55247e..a2b4231 100644 --- a/tools/help_scripts/check_java_home_and_path_in_batch.sh +++ b/tools/help_scripts/check_java_home_and_path_in_batch.sh @@ -68,7 +68,7 @@ expect { expect -re "$|#" { send "which java\r"} expect { - "$JAVA_HOME_VALUE" {send_user "success to update PATH\n";} + "${JAVA_HOME_VALUE}/bin/java" {send_user "success to update PATH\n";} timeout {send_user "time out to which java\n"; exit 5} } expect -re "$|#" { send "logout\r"} -- Gitee From 9914694f8108c9b8956567eed079b7c5739175c1 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Mon, 15 Jul 2024 15:58:53 +0800 Subject: [PATCH 17/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/check_java_home_and_path_in_batch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/help_scripts/check_java_home_and_path_in_batch.sh b/tools/help_scripts/check_java_home_and_path_in_batch.sh index a2b4231..f6ebec3 100644 --- a/tools/help_scripts/check_java_home_and_path_in_batch.sh +++ b/tools/help_scripts/check_java_home_and_path_in_batch.sh @@ -40,7 +40,7 @@ function connect_host_and_check_bisheng_jdk() { local ip=$1 local passwd=$2 /usr/bin/expect << EOF -set timeout 10 +set timeout 5 send_user "$USER@$ip:create dir" spawn ssh $USER@$ip expect { -- Gitee From 90014cfa0264341b792d39cf6bd07e260e6c79c7 Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Mon, 15 Jul 2024 17:51:16 +0800 Subject: [PATCH 18/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../check_java_home_and_path_in_batch.sh | 22 +++++++++++-------- .../update_to_bisheng_jdk_in_batchs.sh | 21 +++++++++--------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/tools/help_scripts/check_java_home_and_path_in_batch.sh b/tools/help_scripts/check_java_home_and_path_in_batch.sh index f6ebec3..70872fa 100644 --- a/tools/help_scripts/check_java_home_and_path_in_batch.sh +++ b/tools/help_scripts/check_java_home_and_path_in_batch.sh @@ -40,12 +40,12 @@ function connect_host_and_check_bisheng_jdk() { local ip=$1 local passwd=$2 /usr/bin/expect << EOF -set timeout 5 -send_user "$USER@$ip:create dir" +set timeout 10 +send_user "$USER@$ip:check java" spawn ssh $USER@$ip expect { "*yes/no" {send "yes\r";exp_continue} - "Permission denied, please try again" {send_user "Permission denied to login user:$USER"; exit 1;} + "Permission denied, please try again" {send_user "Permission denied to login user:$USER\n"; exit 1;} "*password" {send "$passwd\r";exp_continue} "*Password" {send "$passwd\r";exp_continue} "Enter passphrase for key*" {send "$passwd\r";exp_continue} @@ -53,25 +53,29 @@ expect { timeout {send_user "time out to login user:$USER\n"; exit 2} } -expect -re "$|#" { send "if \[ -d $JAVA_HOME_VALUE \];then echo \"True\"; else echo \"False\";fi\r"} +expect -re "\[\$#\]" { send "ls $JAVA_HOME_VALUE \r"} expect { - "True" {send_user "success to copy bisheng jdk to server\n";} - "False" {send_user "failed to copy bisheng jdk to server\n";exit 3} + -nocase "no such file or directory" {send_user "failed to copy bisheng jdk to server\n";exit 3} + -re "\[\$#\]" { + send_user "success to copy bisheng jdk to server\n"; + send "env|grep JAVA_HOME\r"; + } timeout {send_user "time out to -d"; exit 3} } -expect -re "$|#" { send "env|grep JAVA_HOME\r"} expect { "$JAVA_HOME_VALUE" {send_user "success to update JAVA_HOME\n";} + -re "\[\$#\]" {send_user "time out to env JAVA_HOME\n"; exit 4} timeout {send_user "time out to env JAVA_HOME\n"; exit 4} } -expect -re "$|#" { send "which java\r"} +expect -re "\[\$#\]" { send "which java\r"} expect { "${JAVA_HOME_VALUE}/bin/java" {send_user "success to update PATH\n";} + -re "\[\$#\]" {send_user "time out to which java\n"; exit 5} timeout {send_user "time out to which java\n"; exit 5} } -expect -re "$|#" { send "logout\r"} +expect -re "\[\$#\]" { send "logout\r"} expect eof EOF } diff --git a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh index e0460d9..06cd7b6 100644 --- a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh +++ b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh @@ -56,18 +56,18 @@ send_user "$USER@$ip:create dir" spawn ssh $USER@$ip expect { "*yes/no" {send "yes\r";exp_continue} - "Permission denied, please try again" {send_user "Permission denied to login user:$USER"; exit 1;} + "Permission denied, please try again" {send_user "Permission denied to login user:$USER\n"; exit 1;} "*password" {send "$passwd\r";exp_continue} "*Password" {send "$passwd\r";exp_continue} "Enter passphrase for key*" {send "$passwd\r";exp_continue} "Last login:" {send_user "success to login"} timeout {send_user "time out to login user:$USER"; exit 2} } -expect -re "$|#" { send "mkdir -p $TARGET_DIR\r"} -expect -re "$|#" { send "logout\r"} +expect -re "\[\$#\]" { send "mkdir -p $TARGET_DIR\r"} +expect -re "\[\$#\]" { send "logout\r"} set timeout 120 -expect -re "$|#" +expect -re "\[\$#\]" spawn scp -r $BISHENG_TAR_DIR/$BISHENG_JDK_TAR $USER@$ip:$TARGET_DIR expect { "*yes/no" {send "yes\r";exp_continue} @@ -80,7 +80,7 @@ expect { set timeout 20 -expect -re "$|#" +expect -re "\[\$#\]" spawn scp -r unpack_and_modify.sh $USER@$ip:$TARGET_DIR expect { "*yes/no" {send "yes\r";exp_continue} @@ -92,7 +92,7 @@ expect { } set timeout 10 -expect -re "$|#" +expect -re "\[\$#\]" spawn ssh $USER@$ip expect { "*yes/no" {send "yes\r";exp_continue} @@ -103,14 +103,15 @@ expect { "Last login:" {send_user "success to login"} timeout {send_user "time out to login user:$USER"; exit 2} } -expect -re "$|#" { send "bash ${TARGET_DIR}/unpack_and_modify.sh ${BISHENG_JDK_TAR} ${BISHENG_DIR} ${TARGET_DIR}\r"} +expect -re "\[\$#\]" { send "bash ${TARGET_DIR}/unpack_and_modify.sh ${BISHENG_JDK_TAR} ${BISHENG_DIR} ${TARGET_DIR}\r"} expect { "success" {send_user "success to unpack_and_modify"} + -re "\[\$#\]" {send_user "time out to unpack_and_modify:$USER"; exit 2} timeout {send_user "time out to unpack_and_modify:$USER"; exit 2} } -expect -re "$|#" { send "rm -rf $TARGET_DIR/$BISHENG_JDK_TAR\r"} -expect -re "$|#" { send "rm -rf $TARGET_DIR/unpack_and_modify.sh\r"} -expect -re "$|#" { send "logout\r"} +expect -re "\[\$#\]" { send "rm -rf $TARGET_DIR/$BISHENG_JDK_TAR\r"} +expect -re "\[\$#\]" { send "rm -rf $TARGET_DIR/unpack_and_modify.sh\r"} +expect -re "\[\$#\]" { send "logout\r"} expect eof EOF } -- Gitee From bb2b91039e0a069620170c86a08ceefe19d93c7e Mon Sep 17 00:00:00 2001 From: zoupanpan Date: Mon, 15 Jul 2024 18:01:25 +0800 Subject: [PATCH 19/19] =?UTF-8?q?=E7=BC=96=E5=86=99=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=20=E5=BF=AB=E9=80=9F=E5=AE=89=E8=A3=85bishen?= =?UTF-8?q?gJKD=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh index 06cd7b6..f86ee0c 100644 --- a/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh +++ b/tools/help_scripts/update_to_bisheng_jdk_in_batchs.sh @@ -66,7 +66,7 @@ expect { expect -re "\[\$#\]" { send "mkdir -p $TARGET_DIR\r"} expect -re "\[\$#\]" { send "logout\r"} -set timeout 120 +set timeout 240 expect -re "\[\$#\]" spawn scp -r $BISHENG_TAR_DIR/$BISHENG_JDK_TAR $USER@$ip:$TARGET_DIR expect { @@ -78,8 +78,6 @@ expect { timeout {exit 2} } -set timeout 20 - expect -re "\[\$#\]" spawn scp -r unpack_and_modify.sh $USER@$ip:$TARGET_DIR expect { @@ -91,7 +89,6 @@ expect { timeout {exit 2} } -set timeout 10 expect -re "\[\$#\]" spawn ssh $USER@$ip expect { -- Gitee