Skip to content

Instantly share code, notes, and snippets.

@alice-xu
Created May 24, 2014 04:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alice-xu/49949bee0d32b259733a to your computer and use it in GitHub Desktop.
Save alice-xu/49949bee0d32b259733a to your computer and use it in GitHub Desktop.
Custom script for script.vfs.fs.discovery on my Zabbix.
#!/bin/env bash
{
echo "{"
echo " \"data\":["
while read -r line; do
FSNAME=$(echo $line|awk '{print $2}'|sed -e 's/\\/\\\\/g' -e 's|/|\\/|g')
FSTYPE=$(echo $line|awk '{print $3}')
FSDEV=$(echo $line|awk '{print $1}'|sed -e 's/\\/\\\\/g' -e 's|/|\\/|g')
BDNAME=$( \
basename $(readlink $(echo $line|awk '{print $1}')) 2> /dev/null \
|| basename $(echo $line|awk '{print $1}') \
)
echo " {"
echo " \"{#FSNAME}\":\"${FSNAME}\","
echo " \"{#FSTYPE}\":\"${FSTYPE}\","
echo " \"{#FSDEV}\":\"${FSDEV}\","
echo " \"{#BDNAME}\":\"${BDNAME}\""
echo " },"
done < /etc/mtab | sed -e '$d'
echo " }"
echo " ]"
echo "}"
}
@trevormac789
Copy link

thanks. That was very helpful.

I didn't need fsdev or bdname and also

FSNAME=$(echo $line|awk '{print $2}'|sed -e 's/\/\\/g' -e 's|/|\/|g')

should be

FSNAME=$(echo $line|awk '{print $2}'|sed -e 's/\/\\/g' -e 's|/|/|g')

Otherwise it inserts a backslash between each directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment