I need your help again.
In my job we often need to log in to a customer system and verify a thing or two. I Automated the General Health-check we need to perform with every login, with the script below, and it works well.
It needs to be in one-liner form because we can't upload it as a file on to the machine.
However, I decided to color code the output to make it even nicer, but color color doesn't apply for the text inside the "for" loop.
I have some very basic understanding of quotes as follow:
Double quotes("these") allow special characters to be noticed/obeyed.
Single quotes('these') make the interpreting shell ignore all special characters
This lead me to think that issue comes from the single quotes('these') withing which I nested the "if" statement containing the "echo -e" commands. I have tried with "printf", but color coding still doesn't work.
If I remove/replace the single quotes, the script doesn't work. After "ssh module-$i" is executed, script terminates.
I tried replacing the single quotes('these') with double parenthesis"((these))", or back single quotes(`these`) with no success - still doesn't work.
Any idea how I can rewrite the code so it works?
Here comes the code:
MDLCNT=$((`xcli.py module_list | wc -l`-2)); \
CE=`tput sgr0`; \
RED=`tput setaf 1`; \
GREEN=`tput setaf 2`; \
YELLOW=`tput setaf 3`; \
echo ""; \
echo -e "${YELLOW}-----VERSION_GET----${CE}"; xcli.py version_get; echo ""; \
echo -e "${YELLOW}-----STATE_LIST----${CE}"; xcli.py state_list; echo ""; \
echo -e "${YELLOW}-----COMPONENT_LIST FILTER=NOTOK---${CE}"; xcli.py component_list filter=notok; \
echo ""; \
echo -e "${YELLOW}-----ATS_LIST----${CE}"; xcli.py ats_list; echo ""; \
echo -e "${YELLOW}-----UPS_LIST----${CE}"; xcli.py ups_list -f component_id,status,ups_status,currently_functioning,input_power_on,battery_charge_level,last_self_test_result; \
echo ""; \
echo -e "${YELLOW}-----PSU_LIST----${CE}"; xcli.py psu_list; \
echo ""; \
echo -e "${YELLOW}-----MODULE LIST----${CE}"; xcli.py module_list -f component_id,status,currently_functioning,temperature; \
echo ""; \
echo -e "${YELLOW}-----NODE_LIST ALIVE=NO----${CE}"; xcli.py node_list alive=no; \
echo ""; \
echo -e "${YELLOW}-----SERVICE_LIST----${CE}"; xcli.py service_list; \
echo ""; \
echo -e "${YELLOW}-----/ETC/HOSTS----${CE}"; echo "Module IP Module ID"; echo "---------- ----------"; cat /etc/hosts | grep "1-Module-"; \
for ((i = 1; i <= $MDLCNT; i++)); do echo ""; \
ssh module-$i 'if [[ "$?" -eq "0" ]]; then echo -e "${GREEN}Module:'$i' is reachable${CE}" && ls -hl /xiv/conf | grep "prevent" && echo "PSI found in /xiv/conf/ on Module:'$i'" || echo "No PSI found on Module:'$i'"; \
ls -hl /tmp | grep "nodes_not_safe_to_kill" && echo -e"${RED}WARNING! nodes_not_safe_to_kill found in /tmp/ on Module:'$i'${CE}" || echo -e "${GREEN}ZERO nodes_not_safe_to_kill in /tmp/ on Module:'$i'. That is good.${CE}"; fi'; done; \
echo ""; echo -e "${YELLOW}-----SEARCH EVENT_PROC -b -1000 FOR \"FAILED\"----${CE}"; event_proc.py -b -1000 | awk '!/USER_HAS_FAILED_TO_RUN_COMMAND/ && !/USER_LOGIN_HAS_FAILED/ && /failed/';
Aucun commentaire:
Enregistrer un commentaire