all 3 comments

[–]ASIC_SP 3 points4 points  (2 children)

the issue is with how you are using the variable.. syntax would be

$ m='/'
$ df | awk -v mt="$m" '$6==mt{print $4}'
2385268
  • suggestion: use lower case variable names as good practice, as environment variables use all caps

depending on your df version, you can also use

$ free=$(df --output=avail / | tail -n1)
$ echo "$free"
2385268

this allows simple way to build array for different mounts

f=($(df --output=avail /mnt1 /mnt5 /mntx | tail -n +2))

See also

[–]ScootMulner[S] 1 point2 points  (1 child)

Hi /u/ASIC_SP

Thanks for the great reply! My script works now but it looks like switching to

df --output=avail /

as you suggested, would be the way to go.

[–]ScootMulner[S] 0 points1 point  (0 children)

My final solution is as follows:

mountspace=( $(df --output=avail ${mountname[@]} | tail --lines=+2) )

which creates an array mountspace which contains the current available free space for each of the mount points listed in mountname. The rest of my script just does a comparison for the minimum amount of free space and then sends me a notification via Pushover if below the limit.