Add FoundationDB stuff
[slow/toolbox.git] / smbd-trace.sh
1 #!/bin/sh
2
3 #
4 # Trace syscalls and network traffic of a SMB client by IP
5 #
6
7 trap cleanup SIGINT SIGTERM EXIT
8
9 cleanup() {
10     if [ -n $TCPDUMP_PID ] ; then kill $TCPDUMP_PID ; fi
11     if [ -n $STRACE_PID ] ; then kill $STRACE_PID ; fi
12 }
13
14 if [ $# -ne 2 ] ; then
15     echo "Usage: smbd-trace.sh IFACE IP"
16     exit 1
17 fi
18
19 type ls >/dev/null 2>&1 || {
20     echo "Need smbstatus"
21     exit 1
22 }
23
24 IFACE=$1
25 IP=$2
26
27 SMBD_PID=$(/home/slow/git/samba/scratch/bin/smbstatus -p | grep "ipv4:$IP" | cut -d " " -f 1)
28
29 echo Writing strace to smbd-$SMBD_PID.strace
30 echo Writing network trace to smbd-$SMBD_PID.pcap
31
32 tcpdump -i $IFACE -w smbd-$SMBD_PID.pcap host $IP and port 445 > /dev/null 2>&1 &
33 TCPDUMP_PID=$!
34
35 strace -vttT -o smbd-$SMBD_PID.strace -p $SMBD_PID > /dev/null 2>&1 &
36 STRACE_PID=$!
37
38 printf "\nPress ctrl-c to stop tracing...\n"
39 sleep 1000000