Created
May 24, 2014 04:44
-
-
Save alice-xu/49949bee0d32b259733a to your computer and use it in GitHub Desktop.
Custom script for script.vfs.fs.discovery on my Zabbix.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.