From e0c4e3dfb22f3d1be2ce1ab9bf5003c8ccce618d Mon Sep 17 00:00:00 2001 From: sunboquan Date: Mon, 19 Jun 2023 21:38:51 +0800 Subject: [PATCH] tool for modifying hostname --- debug/tools/distribute_modify_hostname.bash | 49 +++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 debug/tools/distribute_modify_hostname.bash diff --git a/debug/tools/distribute_modify_hostname.bash b/debug/tools/distribute_modify_hostname.bash new file mode 100644 index 000000000..3ec6dca3c --- /dev/null +++ b/debug/tools/distribute_modify_hostname.bash @@ -0,0 +1,49 @@ +#!/bin/bash + +SSH="ssh -o StrictHostKeyChecking=no" + +# Modify hostname +change_hostname() +{ + local node="$1" + local user="$2" + local passwd="$3" + sshpass -p "${passwd}" ${SSH} ${user}@${node} hostname "${user}-${node}" +} + +# Get node list in the cluster. +get_cluster_list() +{ + local cluster_config=$1 + cat ${cluster_config} | python3 -c 'import sys,json;[print(node) for node in json.load(sys.stdin)["cluster"].keys()]' +} + +# Get the user from node +get_node_user() +{ + local cluster_config=$1 + local node=$2 + cat ${cluster_config} | python3 -c 'import sys,json;print(json.load(sys.stdin)["cluster"]['\"${node}\"']["user"])' +} + +# Get the password from node +get_node_passwd() +{ + local cluster_config=$1 + local node=$2 + cat ${cluster_config} | python3 -c 'import sys,json;print(json.load(sys.stdin)["cluster"]['\"${node}\"']["passwd"])' +} + +cluster_account_config_path=$1 + +node_list=$(get_cluster_list ${cluster_account_config_path}) +echo"-------begin--------" + +for node in ${node_list} +do + user=$(get_node_user ${cluster_account_config_path} ${node}) + passwd=$(get_node_passwd ${cluster_account_config_path} ${node}) + echo "--------------${user}@${node}----------------" + $(change_hostname ${node} ${user} ${passwd}) + echo "---" +done \ No newline at end of file -- Gitee