Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I will be getting some shell scripts that I, kind of, dont know what they will be doing. But I need to know what I/O operations the script performs (e.g. files they read/access,files they write, folders created...etc).

An example is using strace as follows:

INPUT script: g++ -Wall a.cpp -o hello

I will run it as: sudo strace -f -e trace=open g++ -Wall a.cpp -o hello 2> output.txt

*WHAT I WANT: * output.txt will have the trace and which files had been accessed (a.cpp and b.h which is used in a.cpp, and output hello)

... 
[pid 13871] open("a.cpp", O_RDONLY|O_NOCTTY|O_LARGEFILE) = 3 
[pid 13871] open("b.h", O_RDONLY|O_NOCTTY|O_LARGEFILE) = 4 
... 
[pid 13874] open("hello", O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
...

Problem

1- strace doesnt handle pipe so if I get a command like mkdir d2 | cp *.c d2/ it will only detect the first command mkdir d2.

2- strace provide too much info which is fine but if something is more concrete that would be great!

I searched for other tools and utils, and most of them would list info for a running process and I dont want that since the script will be executed immediately and nothing would be in the process list in Ubuntu.

Any ideas on how can I achieve this in Ubuntu?

share|improve this question

1 Answer 1

Regarding problem 1,

the reason is that strace doesn't start the process with a shell, for security reasons.

To fix this, you need to wrap the pipe in bash -c ' ... ', replacing bash with your shell:

sudo strace -f -e trace=open bash -c 'mkdir d2 | cp *.c d2/' hello 2> output.txt
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.