4

I created this script, which listens for characters received on a hardcoded pipe, and tries to eval those characters. I call my script loop_executor.sh This is all it contains:

!/bin/bash

while :
do
    x=`cat /tmp/console_test`;
    echo "received $x"
    eval $x
done;

I execute my script with a double click.

I want to see what files this process has open:

> $ pgrep loop_executor.sh
1234

> $ ll /proc/1234/fd
dr-x------ 2 userX domain^users  0 Oct 20 17:57 ./
dr-xr-xr-x 9 userX domain^users  0 Oct 20 17:57 ../
lr-x------ 1 userX domain^users 64 Oct 20 17:57 0 -> /dev/null
l-wx------ 1 userX domain^users 64 Oct 20 17:57 1 -> /dev/null
l-wx------ 1 userX domain^users 64 Oct 20 17:57 2 -> /home/local/groupX/userX/.xsession-errors
lr-x------ 1 userX domain^users 64 Oct 20 17:58 255 -> /home/local/groupX/userX/Desktop/loop_executor.sh*
lr-x------ 1 userX domain^users 64 Oct 20 17:57 3 -> pipe:[225812]

FD 3 points to a "pipe". Well i know what file it uses, because I'm the one that hardcoded the file in the script, but I'd like to get this information (if possible) from another source (since my script is just a POC, and it could be a process whose code is not open to me).

What I understood, is that pipe:[225812] doesn't point to the inode of my file.

ll -i /tmp/console_test 
16519395 prw-r--r-- 1 userX domain^users 0 Oct 20 18:14 /tmp/console_test|

So my question is: If processess can open pipes, which are files on my system, can I determine which files those pipes "corresponded" to?

I'm using ubuntu 12.04 if that matters.

[EDIT] Found the cat process that was reading from my pipe. It has the same opened pipe as its parent process, so it doesn't make much of a difference here -> i still don't know just by looking at pipe:[225812] what file -if any - that is.

1 Answers1

2

Your script does not have /tmp/console_test opened, the cat process does. Your script is reading from a pipe that is connected to the cat process; that's what you're seeing in your question.

Search for the cat process and check that one out.

You probably want something like this:

while read x; do
    echo "received $x"
    eval "$x"
done < /tmp/console_test

Note the added quotes around the parameter to eval

wurtel
  • 16,115