--
I need to copy each file which a process has open, by reading its file descriptor in the /proc/[pid]/fd/
directory etc. more specifically I need to find the directory of the file for each pid
, then egrep for a regex; files ending in [0-9]$
. cp throws an exception:
cp: cannot stat ‘poop.log.2016-01-08T12-34-10’: No such file or directory
function foo {
local f
logfile="$(logfile_for_pid)" # calls the function to get file descriptor
for f in "$logfile"; do
for i in "$(dirname "$f")"; do
echo "ls the dirname: "$i""
ls "$i" | egrep -e '[0-9]$' | xargs cp -t /tmp
done
done
}
My question would be: how do I pass the ls
output as an argument for cp
?
also; running directly from the terminal. same error! note; I am new to bash!
$ cp `ls "$dir" | egrep -e '[0-9]$'` /tmp