Sample Header Ad - 728x90

Bash shell script output alignment

49 votes
4 answers
73853 views
My script: date echo -e "${YELLOW}Network check${NC}\n\n" while read hostname do ping -c 1 "$hostname" > /dev/null 2>&1 && echo -e "Network $hostname : ${GREEN}Online${NC}" || echo -e "${GRAY}Network $hostname${NC} : ${RED}Offline${NC}" done < list.txt sleep 30 clear done Is outputting info like this: Network 10.x.xx.xxx : Online Network 10.x.xx.xxx : Offline Network 10.x.xx.xxx : Offline Network 10.x.xx.xxx : Offline Network 10.x.xx.x : Online Network 139.xxx.x.x : Online Network 208.xx.xxx.xxx : Online Network 193.xxx.xxx.x : Online which I'd like to clean up to get something like this: Network 10.x.xx.xxx : Online Network 10.x.xx.xxx : Offline Network 10.x.xx.xxx : Offline Network 10.x.xx.x : Online Network 139.xxx.x.x : Online Network 208.xx.xxx.xxx : Online Network 193.xxx.xxx.x : Online Network 193.xxx.xxx.xxx : Offline
Asked by pijaaa (501 rep)
Oct 5, 2017, 08:12 AM
Last activity: Aug 13, 2023, 11:18 AM