I am trying to get these returns using the free and sar command to keep track of the returns which I can then export to excel. So I need every time I run the script to create a line and jump to the next one, but since there are several commands, either put one per line or if I put a tr '\ n' '', no line break in the document.
The other option would be to enter date, hostname and returns in the AWK by means of variable but I have not been able to be recognized by this option:
I need that:
230720 13:58:05 tapi1lll 20366080 519744 97.51
230720 13:58:05 tapi1lll 20366080 519744 97.51
230720 13:58:05 tapi1lll 20366080 519744 97.51
awk -v ' "maquina=$(hostname) -v "fecha=$(date +"%d%m%y %H:%M:%S") /Mem/ { print $3,$4; printf("%.2f \n", $3/$2 * 100.0) } END { print " " } '
#! /bin/bash
ram(){
date +"%d%m%y %H:%M:%S " ;
hostname ;
free | awk ' /Mem/ { print $3,$4; printf("%.2f \n", $3/$2 * 100.0) } END { print " " } '
}
ram | tr '\n' ' '
thank you!