I am making a small program in shell script but the problem is that I cannot print 2 variables in a single line with a good format.
Example:
#!/bin/bash
top=70
espacio_fs=`df -h | tr -s " " "," | cut -d"," -f6 | sed '1d'`
espacio=`df -h | tr -s " " "," | cut -d"," -f5 | tr -s "%" " " | tail -n +2`
for i in $espacio
do
if [ "$i" -le "$top" ] ; then
echo "$espacio_fs" "$espacio" > fss.txt
else
echo "No existen filesystems mayores al 70%"
The result that it throws me in the fss.txt output is:
Filesystem mayores a 70% son:
/
/dump
/tmp
/backup
/oracle
/grid
/boot
/dev/shm
4
8
3
22
85
57
6
31
I need to print that output with the following format
Filesystem mayores a 70% son:
Filesytem Uso(%)
/ 4
/dump 8
/tmp 3
/backup 22
/oracle 85
/grid 57
/boot 6
/dev/shm 31
How can you achieve this connection?
Thank you
First, none of this is necessary. You only need to print columns 1 and 5 of the output d
df
, so do:And to only save lines that have more than 70% usage, first remove the
%
to keep only the figure and then:And, to format it better, use
printf
:If you want to use your script, the problem is that your variables are like this:
That is, your two variables have all the data separated by
\n
, but it doesn't show if you print it without quotes (echo $var
instead of the correctecho "$var"
). So your program works perfectly, but it's not the way to do what you want. You could do something like: