I would like to ask some help how can I improve the basic script below.
So, I was able to pass the arguments to bash, but is it possible for my awk command, to make it more flexible?
I encountered an error in df -h command where it shows 2 lines for 1 filesystem (supposed to be one line only)
and then, the script does not show correct parameters since argument numbers (the $6 and $5) have changed.
Sample:
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/test/test2/test3 1.1G 100M 1G 1% /test
/dev/test/test2/test3/test4
1.1G 100M 1G 1% /tst2
$ cat myscript.sh
#!bin/bash
df -h "$@" | awk '{print $6,"=",$5}' | sed -n '1!p'
$ ./myscript.sh /test /tst2
My output will be
/test=1%
=/tst2
but should be
/test=1%
/tst2=1%
awk '{print $NF,"=",$(NF -1)}'. You can get rid of thesedas well...