-
Notifications
You must be signed in to change notification settings - Fork 1
/
dsk-peek.sh
executable file
·66 lines (53 loc) · 1.17 KB
/
dsk-peek.sh
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
v=""
[[ "$1" = "-v" ]] && v="v" && shift
[[ "$1" = "-vv" ]] && v="vv" && shift
declare -a dn
declare -a dd
declare -a ss
declare -a ddi
i=0
for val in "$@"
do
dn[$i]=$val
b=$(basename "$val")
dv=$(lsblk | grep "^$b" | awk '{print $2}')
dv=${dv//:/,}
dd[$i]="$dv"
ss[$i]=$(cat /sys/block/$b/queue/hw_sector_size)
dn[$i]=$b
ddi[$dv]=$i
(( i++ ))
done
find_dd() {
i=0
for a in "${dd[@]}"
do
[ "$1" = "$a" ] && echo $i && break
((i++))
done
}
#echo "${dn[@]}"
read;read
while read -r tm app pid op dsk blk sz l
do
i=${ddi[$dsk]}
[[ -z "$i" ]] && continue
[[ "$app" = "dd" ]] && continue
((skp = $blk*$ss))
echo "$tm" "$app" "$pid" ${dn[$i]} $op $blk $sz $l
[ -z "$v" ] && continue
dd if=/dev/${dn[$i]} bs=1 skip=$skp count=$sz 2>/dev/null > /tmp/dump.bin
if [ "$sz" -gt 256 ] && [ ! "$v" = "vv" ]; then
head -c 128 /tmp/dump.bin | hexdump -C
(( a = $sz-256 ))
echo --- skiped $a bytes ---
tail -c 128 /tmp/dump.bin | hexdump -C
else
hexdump -C /tmp/dump.bin
fi | while read line
do
echo " $line"
done
echo
done