Добавить значение в конец файла на основе совпадения содержимого

Мой сценарий ниже

###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#

Мой ВЫХОД ниже

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

Мои требования ниже

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
0
25.05.2017, 13:10
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#
1
28.01.2020, 02:46

Теги

Похожие вопросы