This commit is contained in:
gysar1983 2023-02-23 13:59:45 +08:00
parent 8b88ed2aac
commit b1228b653a

View File

@ -1,8 +1,12 @@
#!/bin/bash #!/bin/bash
version="23/02/23"
echo "get-all-logs $version"
PRMT="[$(whoami)@$(hostname -s) ]" PRMT="[$(whoami)@$(hostname -s) ]"
about_platform(){ about_platform(){
for ONE in vm dci; for ONE in vm dci;
do do
test -d /opt/ispsystem/${ONE} && PLATFORM=${ONE}; test -d /opt/ispsystem/${ONE} && PLATFORM=${ONE};
@ -11,9 +15,8 @@ done
if [[ -z "${PLATFORM}" ]]; then if [[ -z "${PLATFORM}" ]]; then
echo "No ISPsystem Software found" && exit; echo "No ISPsystem Software found" && exit;
else else
LOGDIR="${HOME}/${PLATFORM}_logs_$(date +"%Y_%m_%d_%H_%M_%S")" && mkdir -p ${LOGDIR}
LOGDIR="${HOME}/${PLATFORM}_${type_log}_$(date +"%Y_%m_%d_%H_%M_%S")" && mkdir -p ${LOGDIR} ARCNAME=$(date +"${HOME}/${PLATFORM}_logs_%Y_%m_%d_%H_%M_%S.tar.gz")
ARCNAME=$(date +"${HOME}/${PLATFORM}_${type_log}_%Y_%m_%d_%H_%M_%S.tar.gz")
LicenseToken=$(grep -oP '\"LicenseToken\":"[^"]*\"' /opt/ispsystem/${PLATFORM}/config.json | sed -e 's/\"LicenseToken\"://g' -e 's/\"//g') LicenseToken=$(grep -oP '\"LicenseToken\":"[^"]*\"' /opt/ispsystem/${PLATFORM}/config.json | sed -e 's/\"LicenseToken\"://g' -e 's/\"//g')
CurrentVersion=$(grep -oP '\"CurrentVersion\":"[^"]*\"' /opt/ispsystem/${PLATFORM}/config.json | sed -e 's/\"CurrentVersion\"://g' -e 's/\"//g') CurrentVersion=$(grep -oP '\"CurrentVersion\":"[^"]*\"' /opt/ispsystem/${PLATFORM}/config.json | sed -e 's/\"CurrentVersion\"://g' -e 's/\"//g')
Stage=$(grep -oP '\"Stage\":"[^"]*\"' /opt/ispsystem/${PLATFORM}/config.json | sed -e 's/\"Stage\"://g' -e 's/\"//g') Stage=$(grep -oP '\"Stage\":"[^"]*\"' /opt/ispsystem/${PLATFORM}/config.json | sed -e 's/\"Stage\"://g' -e 's/\"//g')
@ -112,31 +115,69 @@ mysql_connect(){
eval $fullcmd; eval $fullcmd;
} }
node_connect() { node_connect() {
ip_addr=$1; ip_addr=$1;
ssh_port=$2; ssh_port=$2;
cmd=$4; cmd=$4;
logfile=$3; logfile=$3;
fullcmd="docker exec --tty --interactive vm_box ssh -o \"StrictHostKeyChecking no\" -i /opt/ispsystem/vm/etc/.ssh/vmmgr.1 $ip_addr -p $ssh_port $cmd >> ${LOGDIR}/$logfile"; testcmd="docker exec --tty --interactive vm_box ssh -o BatchMode=yes -o ConnectTimeout=5 -o \"StrictHostKeyChecking no\" -i /opt/ispsystem/vm/etc/.ssh/vmmgr.1 $ip_addr -p $ssh_port echo ok 2>&1";
echo $fullcmd; echo $testcmd;
echo -e "\n $cmd \n">> ${LOGDIR}/$logfile; status=$(eval $testcmd);
eval $fullcmd; echo $status;
if [[ $status == "ok" ]] ; then
echo "node $ip_addr on $node_port connected!";
fullcmd="docker exec --tty --interactive vm_box ssh -o \"StrictHostKeyChecking no\" -i /opt/ispsystem/vm/etc/.ssh/vmmgr.1 $ip_addr -p $ssh_port $cmd >> ${LOGDIR}/$logfile";
echo $fullcmd;
echo -e "\n $cmd \n">> ${LOGDIR}/$logfile;
eval $fullcmd;
elif [[ $status == "Permission denied"* ]] ; then
echo "node $ip_addr on $node_port not authorized!";
else
echo "node $ip_addr on $node_port not connected!";
fi
} }
_help(){ _help(){
cat <<- EOF echo -e "Usage : $0 -type";
============================================ echo -e "\n available types:\n\n";
Usage : get-all-logs -type echo -e "-logs or 1";
echo -e "-short-logs or 2";
echo -e "-lic or 3";
echo -e "-node or 4 \<IP-address\> \<SSH-port\>";
available types: PS3='Please enter your choice(enter number): '
-logs or 1 options=("Full logs" "Short logs" "License\'s logs" "Node\'s logs" "Quit")
-short-logs or 2 select opt in "${options[@]}"
-lic or 3 do
-node or 4 <IP-address> <SSH-port> case $opt in
"Full logs")
_logs;
break;
;;
"Short logs")
_short_logs;
break;
;;
"License\'s logs")
_lic;
break;
;;
"Node\'s logs")
read -p "Enter IP address: " node_ip
read -p "Enter port: " node_port
_node $node_ip $node_port;
break;
;;
"Quit")
break
;;
*) echo "invalid option $REPLY";;
esac
done
=============================================
EOF
} }
_logs() { _logs() {
@ -213,32 +254,23 @@ _node() {
finish; finish;
} }
about_platform;
if [[ "$1" == "-logs" || "$1" == "1" ]]; then if [[ "$1" == "-logs" || "$1" == "1" ]]; then
type_log="logs";
about_platform;
_logs; _logs;
elif [[ "$1" == "-short-logs" || "$1" == "2" ]]; then elif [[ "$1" == "-short-logs" || "$1" == "2" ]]; then
type_log="short-logs";
about_platform;
_short_logs; _short_logs;
elif [[ "$1" == "-lic" || "$1" == "3" ]]; then elif [[ "$1" == "-lic" || "$1" == "3" ]]; then
type_log="lic";
about_platform;
_lic; _lic;
elif [[ "$1" == "-node" || "$1" == "4" ]]; then elif [[ "$1" == "-node" || "$1" == "4" ]]; then
type_log="node";
about_platform;
if [[ -z $2 || -z $3 ]]; then if [[ -z $2 || -z $3 ]]; then
echo "please set IP address and port of node!"; echo "please set IP address and port of node!";
exit; exit;
else else
_node $2 $3; _node $2 $3;
fi fi
elif [[ "$1" == "-vm-host" || "$1" == "5" ]]; then #elif [[ "$1" == "-vm-host" || "$1" == "5" ]]; then
type_log="vm-host"; # _vm_host;
about_platform;
_vm_host;
else else
_help; _help;
fi fi