Anexar valor ao final do arquivo com base no conteúdo da correspondência

0

Meu script abaixo

###BEGIN#
#!/bin/bash
### Daily Volume Growth
echo "Volume Name     Total Size   'date +%F'" >> volgrow

echo "'ssh 192.168.1.2 df -h Volume1 |head -2 | tail -1 | awk '{ print $1,$2 }''" >> volgrow
echo "'ssh 192.168.1.2 df -h Volume2 |head -2 | tail -1 | awk '{ print $1,$2 }''" >> volgrow
echo "'ssh 192.168.1.2 df -h Volume3 |head -2 | tail -1 | awk '{ print $1,$2 }''" >> volgrow
###END#

Meu OUTPUT está abaixo

Volume Name     Total Size 2017-05-25
/vol/Volume1/ 5632GB
/vol/Volume2/ 2136GB
/vol/Volume3/ 5110GB

Meu requisito está abaixo

Volume Name     Total Size 2017-05-25  2017-05-26 2017-05-27
/vol/Volume1/ 5632GB  5633GB 5630GB
/vol/Volume2/ 2136GB  2137GB 2138GB
/vol/Volume3/ 5110GB 5109GB 5111GB
    
por Ravi Ankam 25.05.2017 / 11:12

1 resposta

1

###BEGIN#
#!/bin/bash
### Daily Volume Growth
#### Will execute once when file not exist and add first entry in the file
if [ ! -f volgrow ]; then
      echo "Volume Name     Total Size   'date +%F'" >> volgrow
    echo "'ssh 192.168.1.2 df -h Volume1 |head -2 | tail -1 | awk '{ 
print $1,$2 }''" >> volgrow
    echo "'ssh 192.168.1.2 df -h Volume2 |head -2 | tail -1 | awk '{ 
print $1,$2 }''" >> volgrow
    echo "'ssh 192.168.1.2 df -h Volume3 |head -2 | tail -1 | awk '{ 
print $1,$2 }''" >> volgrow
fi

#### get all data in different variables 
line1 = echo "'date +%F'"
line2 = "'ssh 192.168.1.2 df -h Volume1 |head -2 | tail -1 | awk '{ print $1,$2 }''   "
line3 = "'ssh 192.168.1.2 df -h Volume2 |head -2 | tail -1 | awk '{ print $1,$2 }''   "
line4 = "'ssh 192.168.1.2 df -h Volume3 |head -2 | tail -1 | awk '{ print $1,$2 }''   "

###########  append variable value in line 1, 2, 3, 4
sed -i -e "1s%$%\t$line1%" volgrow
sed -i -e "2s%$%$line2%" volgrow
sed -i -e "3s%$%$line3%" volgrow
sed -i -e "4s%$%$line4%" volgrow
###END#
    
por 25.05.2017 / 15:16