From 935bf8c40137a389aa49941c6a18e6907fbb06aa Mon Sep 17 00:00:00 2001 From: NewName Date: Wed, 27 Mar 2024 20:42:27 +0800 Subject: [PATCH] Update ssh.sh --- ssh.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ssh.sh b/ssh.sh index c19e744..02a9116 100644 --- a/ssh.sh +++ b/ssh.sh @@ -1,5 +1,9 @@ #!/bin/bash +# 定义颜色输出 +green='\033[0;32m' +none='\033[0m' # 没有颜色 + # 检查并安装 sshpass if ! command -v sshpass &> /dev/null; then echo "sshpass could not be found, attempting to install..." @@ -34,8 +38,13 @@ while true; do # 读取服务器信息并执行命令 while IFS=' ' read -r ip port user password; do - echo "Connecting to $ip..." + echo -e "Connecting to ${green}$ip${none}..." sshpass -p "$password" ssh -o StrictHostKeyChecking=no -p "$port" "$user@$ip" "$command" + if [ $? -eq 0 ]; then + echo -e "Command executed successfully on ${green}$ip${none}." + else + echo -e "Failed to execute command on ${green}$ip${none}." + fi done < "$server_info_file" # 询问用户是否继续输入另一个命令