1 | #!/bin/ksh |
---|
2 | # |
---|
3 | # Usage : filehist |
---|
4 | # |
---|
5 | # Shell script will process required environment variables and |
---|
6 | # analyze GPFS filesystems which are mounted |
---|
7 | # |
---|
8 | |
---|
9 | PATH=/tmp/mmfs:/usr/lpp/mmfs/bin:/usr/lpp/mmfs/samples/util:/usr/lpp/mmfs/samples/debugtools:/usr/sbin:/bin:$PATH |
---|
10 | #check for required commands |
---|
11 | if ! which tsinode 1>/dev/null |
---|
12 | then |
---|
13 | print "filehist: tsinode not found. Run 'make tsinode' in /usr/lpp/mmfs/samples/util" |
---|
14 | return 1 |
---|
15 | fi |
---|
16 | if ! which tsfilehist.awk 1>/dev/null |
---|
17 | then |
---|
18 | print "filehist: /usr/lpp/mmfs/samples/debugtools/tsfilehist.awk not found" |
---|
19 | return 2 |
---|
20 | fi |
---|
21 | |
---|
22 | #get mount points for GPFS filesystems |
---|
23 | opsys=$(uname -s) |
---|
24 | if [[ $opsys = AIX ]]; then |
---|
25 | mtpts=$(mount|awk '$3 == "mmfs" {print $2":"substr($1,6)}') |
---|
26 | elif [[ $opsys = Linux ]]; then |
---|
27 | mtpts=$(mount|awk '$5 == "gpfs" {print $3":"substr($1,6)}') |
---|
28 | else |
---|
29 | print "$opsys not AIX or Linux" |
---|
30 | return 1 |
---|
31 | fi |
---|
32 | echo "Getting file histogram for: $mtpts" |
---|
33 | |
---|
34 | #get free space, blocksize of the filesystem, and nsd's |
---|
35 | for mf in $mtpts; do |
---|
36 | mp=${mf%:*}; fs=${mf#*:} |
---|
37 | df=$(df -k $mp | tail -1 | awk '{print $2 "k"}') |
---|
38 | blksz=$(tslsfs $fs -B | tail -1 | awk '{print $2/1024}') |
---|
39 | diskls="$(tslsdisk $fs -i 2>/dev/null)" |
---|
40 | integer disks=$(echo "$diskls"| wc -l) |
---|
41 | let bk=disks |
---|
42 | let bk4m=4096/blksz |
---|
43 | [[ $bk -lt $bk4m ]] && bk=$bk4m |
---|
44 | [[ $bk -lt 100 ]] && bk=100 |
---|
45 | echo "Writing output to $fs.filesum " |
---|
46 | echo "=======================\n$fs: $(hostname) $(date)\n=======================\n" > $fs.filesum |
---|
47 | df -k $mp >> $fs.filesum |
---|
48 | echo "\n" >> $fs.filesum |
---|
49 | mmlsfs $fs >> $fs.filesum |
---|
50 | echo "\n\n$diskls\n\n" >> $fs.filesum |
---|
51 | echo "Background: tsinode $mp | tsfilehist.awk availablespace=$df nbuckets=$bk blocksize=$blksz" |
---|
52 | tsinode $mp | tsfilehist.awk availablespace=$df nbuckets=$bk blocksize=$blksz >> $fs.filesum & |
---|
53 | |
---|
54 | done |
---|
55 | echo "Waiting for background processes to complete" |
---|
56 | wait |
---|