diff --git a/get-all-logs.sh b/get-all-logs.sh index 9bb5fe9..1d6af76 100755 --- a/get-all-logs.sh +++ b/get-all-logs.sh @@ -1,8 +1,12 @@ #!/bin/bash +version="23/02/23" +echo "get-all-logs $version" + PRMT="[$(whoami)@$(hostname -s) ]" about_platform(){ + for ONE in vm dci; do test -d /opt/ispsystem/${ONE} && PLATFORM=${ONE}; @@ -11,9 +15,8 @@ done if [[ -z "${PLATFORM}" ]]; then echo "No ISPsystem Software found" && exit; else - - LOGDIR="${HOME}/${PLATFORM}_${type_log}_$(date +"%Y_%m_%d_%H_%M_%S")" && mkdir -p ${LOGDIR} - ARCNAME=$(date +"${HOME}/${PLATFORM}_${type_log}_%Y_%m_%d_%H_%M_%S.tar.gz") + LOGDIR="${HOME}/${PLATFORM}_logs_$(date +"%Y_%m_%d_%H_%M_%S")" && mkdir -p ${LOGDIR} + ARCNAME=$(date +"${HOME}/${PLATFORM}_logs_%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') 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') @@ -112,31 +115,69 @@ mysql_connect(){ eval $fullcmd; } + node_connect() { ip_addr=$1; ssh_port=$2; cmd=$4; 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"; - echo $fullcmd; - echo -e "\n $cmd \n">> ${LOGDIR}/$logfile; - eval $fullcmd; + 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 $testcmd; + status=$(eval $testcmd); + 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(){ - cat <<- EOF -============================================ - Usage : get-all-logs -type +echo -e "Usage : $0 -type"; +echo -e "\n available types:\n\n"; +echo -e "-logs or 1"; +echo -e "-short-logs or 2"; +echo -e "-lic or 3"; +echo -e "-node or 4 \ \"; - available types: +PS3='Please enter your choice(enter number): ' - -logs or 1 - -short-logs or 2 - -lic or 3 - -node or 4 +options=("Full logs" "Short logs" "License\'s logs" "Node\'s logs" "Quit") +select opt in "${options[@]}" + do + 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() { @@ -213,32 +254,23 @@ _node() { finish; } +about_platform; + if [[ "$1" == "-logs" || "$1" == "1" ]]; then - type_log="logs"; - about_platform; _logs; elif [[ "$1" == "-short-logs" || "$1" == "2" ]]; then - type_log="short-logs"; - about_platform; _short_logs; elif [[ "$1" == "-lic" || "$1" == "3" ]]; then - type_log="lic"; - about_platform; _lic; elif [[ "$1" == "-node" || "$1" == "4" ]]; then - type_log="node"; - about_platform; if [[ -z $2 || -z $3 ]]; then echo "please set IP address and port of node!"; exit; else _node $2 $3; fi -elif [[ "$1" == "-vm-host" || "$1" == "5" ]]; then - type_log="vm-host"; - about_platform; - _vm_host; - +#elif [[ "$1" == "-vm-host" || "$1" == "5" ]]; then +# _vm_host; else _help; fi \ No newline at end of file