I have the following script in works:
#!/bin/bash
IFS=$(echo -en "\n\b")
echo -e "----------------------------------------------------------------------------------------------"
echo -e "| Job Name | Enabled | Client Names | Retention | Schedule | Type |"
echo -e "----------------------------------------------------------------------------------------------"
vcenter_name=$(cat /usr/local/vdr/etc/vcenterinfo.cfg | grep vcenter-hostname | cut -d '=' -f 2)
# To extract job names:
job_name=$(mccli group show --recursive=true | grep -i "/$vcenter_name/VirtualMachines" | awk -F/. '{print $(NF-2)}')
for i in $job_name
do
enabled=$(mccli group show --name=/$vcenter_name/VirtualMachines/$i | grep Enabled | awk '{print $NF}')
client_name=$(mccli group show-members --name=/vcenter-prod.happycow.local/VirtualMachines/$i | awk '{print $3}' | tail -n +4 | awk -F/ '{print $NF}')
printf "| %-27s | %7s | %7s | %10s | %7s | %12s |\n" "$i" "$enabled" "$client_name"
done
The script runs great but needs some formatting. The output I get now is:
----------------------------------------------------------------------------------------------
| Job Name | Enabled | Client Names | Retention | Schedule | Type |
----------------------------------------------------------------------------------------------
| Backup With Space | true | Space | | | |
| Disk-Level | true | | | | |
| Linux-VM | true | | | | |
| Partial | true | | | | |
| Prod-Backup | false | VM-B
VM-D | | | |
| Same-Host | true | | | | |
| Temp | true | esxi02
ESXi-6.5
ESXi6GA | | | |
I would like to see it as:
----------------------------------------------------------------------------------------------
| Job Name | Enabled | Client Names | Retention | Schedule | Type |
----------------------------------------------------------------------------------------------
| Backup With Space | true | Space | | | |
| Disk-Level | true | | | | |
| Linux-VM | true | | | | |
| Partial | true | | | | |
| Prod-Backup | false | VM-B | | | |
| VM-D | | | |
| Same-Host | true | | | | |
| Temp | true | esxi02
| ESXi6.5
| ESXi6GA | | | |
Ignore the | alignment. I can take care of that one.
So basically, I would like to have the multi value / multi line output of job_name variable under a single column.
awkorperl(or anything else but sh or bash) - trying to do it in bash will result in an unreadable mess. BTW,perlhas great built-in report writing capabilities (seeman perlform). 2. we need to sample input, not just the desired output. 3. some basic bash/shell tips: useIFS=$'\n\b', notIFS=$(echo "\n\b"); there's no need to pipe cat into grep or grep into awk - both are capable of reading files withoutcat's help. e.g.vcenter_name=$(awk -F= '{print $2}' /usr/local/vdr/etc/vcenterinfo.cfg)