statsnoop revision 1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# statsnoop - snoop file stats as they occur.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Written using DTrace (Solaris 10 3/05).
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# $Id: statsnoop 65 2007-10-04 11:09:40Z brendan $
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# USAGE: statsnoop [-a|-A|-ceghlsvxZ] [-f pathname] [-t syscall]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# [-n name] [-p PID]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# statsnoop # default output
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -a # print most data
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -A # dump all data, space delimited
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -c # print cwd of process
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -e # print errno value
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -g # print command arguments
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -l # print syscall type
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -s # print start time, us
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -v # print start time, string
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -x # only print failed stats
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -Z # print zonename
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -f pathname # file pathname to snoop
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -n name # command name to snoop
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -p PID # process ID to snoop
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# -t syscall # stat syscall to trace
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# statsnoop -v # human readable timestamps
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# statsnoop -S # syscall type
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# statsnoop -e # see error codes
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# statsnoop -f /etc/passwd # snoop this file only
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# ZONE Zone name
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# UID User ID
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# PID Process ID
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# PPID Parent Process ID
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# FD file descriptor (-1 for error)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# TYPE syscall type
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# CWD current working directory of process
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# PATH pathname for file stat
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# COMM command name for the process
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# ARGS argument listing for the process
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# TIME timestamp for the stat event, us
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# STRTIME timestamp for the stat event, string
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# SEE ALSO: truss, BSM auditing.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# CDDL HEADER START
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# The contents of this file are subject to the terms of the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Common Development and Distribution License, Version 1.0 only
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# (the "License"). You may not use this file except in compliance
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# with the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# You can obtain a copy of the license at Docs/cddl1.txt
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# See the License for the specific language governing permissions
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# and limitations under the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# CDDL HEADER END
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Author: Brendan Gregg [Sydney, Australia]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# 09-Sep-2007 Brendan Gregg Created this.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin##############################
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# --- Process Arguments ---
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin### Default variables
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinopt_dump=0; opt_file=0; opt_time=0; opt_timestr=0; opt_args=0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinopt_zone=0; opt_cwd=0; opt_failonly=0; opt_err=0; filter=0; pathname=.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinopt_name=0; opt_pid=0; opt_type=0; opt_trace=0; pname=.; pid=0; trace=.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin### Process options
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin USAGE: statsnoop [-a|-A|-ceghlsvxZ] [-f pathname] [-t syscall]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin [-n execname] [-p PID]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin statsnoop # default output
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -a # print most data
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -A # dump all data, space delimited
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -c # print cwd of process
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -e # print errno value
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -g # print command arguments
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -l # print syscall type
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -s # print start time, us
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -v # print start time, string
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -x # only print failed stats
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -Z # print zonename
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -f pathname # pathname name to snoop
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -n name # process name to snoop
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -p PID # process ID to snoop
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin -t syscall # stat syscall to trace
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin statsnoop -v # human readable timestamps
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin statsnoop -e # see error codes
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin statsnoop -f /etc/motd # snoop this file only
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin### Option logic
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [ $opt_dump -eq 1 ]; then
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin opt_zone=0; opt_cwd=0; opt_time=0; opt_timestr=0; opt_type=0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin opt_args=2
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [ $opt_name -eq 1 -o $opt_pid -eq 1 -o $opt_trace -eq 1 ]; then