-
Notifications
You must be signed in to change notification settings - Fork 1
/
mydf
executable file
·46 lines (37 loc) · 1021 Bytes
/
mydf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
SCRIPT=$(readlink -m $(type -p $0))
SCRIPT_DIR=$(dirname ${SCRIPT})
CONFIGFILE=$(readlink -f $SCRIPT_DIR/_config/dirs.txt)
usage() {
cat <<EOF
Usage:
$(basename $0)
Prints percent usage for each filesystem listed in
"$CONFIGFILE".
EOF
}
dfcmd() {
local _dir=$1
local _cmd
read -d '' _cmd << EOF || true
df -HP $_dir | sed -n '2p' | awk 'BEGIN{OFS=",";} { print \$5,\$3 }' | sed 's/%//g' | sed 's/T//g'
EOF
echo $_cmd
}
[[ $1 == "-h" || $1 == "--help" ]] && { usage; exit 1; }
if [ ! -f "$CONFIGFILE" ]; then
echo "Set $CONFIGFILE first"
exit 1
fi
date=("$(date +"%Y-%m-%d %H:%M:%S")")
echo "Datetime,Filesystem,Usage,UsageT"
while read line; do
IFS=":" read server remotepath <<< "$line"
if [ -n "${remotepath-}" ]; then
cmd=$(dfcmd $remotepath)
printf "%s,%s,%s\n" "${date[@]}" $remotepath $(ssh $server "$cmd")
else
cmd=$(dfcmd $line)
printf "%s,%s,%s\n" "${date[@]}" $line $(eval "$cmd")
fi
done <$CONFIGFILE