2012-03-13 15:25:45 +00:00
#!/bin/bash
2012-03-15 21:28:16 +00:00
# NAME
# tracefile - list files being accessed
#
# SYNOPSIS
2012-03-17 01:31:00 +00:00
# tracefile [-aenu] command
2012-03-15 21:28:16 +00:00
#
# DESCRIPTION
# tracefile will print the files being accessed by the command.
#
# OPTIONS
# -a List all files.
#
# -e List only existing files.
#
# -n List only non-existing files.
#
2012-03-17 01:31:00 +00:00
# -u List only files once.
#
2012-03-15 21:28:16 +00:00
# AUTHOR
# Ole Tange <tange@gnu.org>
#
# COPYRIGHT
# Copyright © 2012 Free Software Foundation, Inc. License
# GPLv3+: GNU GPL version 3 or later
# <http://gnu.org/licenses/gpl.html>. This is free software: you
# are free to change and redistribute it. There is NO WARRANTY,
# to the extent permitted by law.
2012-03-13 15:25:45 +00:00
export _EXISTS=0
export _NONEXISTS=0
2012-03-17 01:31:00 +00:00
export _UNIQUE=0
2012-03-13 15:25:45 +00:00
while true ; do
case "$1" in
-e|--exists) export _EXISTS=1; shift ;;
-n|--nonexists) export _NONEXISTS=1; shift ;;
-a|--all) export _EXISTS=1; export _NONEXISTS=1; shift ;;
2012-03-17 01:31:00 +00:00
-u|--unique) export _UNIQUE=1; shift ;;
2012-03-13 15:25:45 +00:00
*) break;
esac
done
if [ "$_EXISTS" == "0" -a "$_NONEXISTS" == "0" ] ; then
export _EXISTS=1
export _NONEXISTS=1
fi
2012-03-17 01:31:00 +00:00
strace -ff -e trace=file "$@" 2>&1 |
perl -ne 's/^[^"]+"(([^\\"]|\\[\\"nt])*)".*/$1/ && do { '$_EXISTS' and -e $1 and (not '$_UNIQUE' or not $seen{$_}++) and print; '$_NONEXISTS' and ! -e $1 and (not '$_UNIQUE' or not $seen{$_}++) and print };'
2012-03-13 15:25:45 +00:00