Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-18-2004, 04:26 PM   #1
Registered: Nov 2003
Location: Ireland
Distribution: Red Hat 9
Posts: 49

Rep: Reputation: 15
bash + strace = .....


this might sound bizarre but I am trying to do something and I need some help. I have downloaded the source code of both bash and strace and want to modify both to do a little playing around. I'd like to modify my bash shell so everytime a command is invoked from the command line, not only is the command executed, but it is also straced, and the result of which saved to a file...

So if I was to type
it would be the equivalent of
strace -o outFileName ls
but all done automatically. As far as I can see this only requires two small (he says awaiting a backlash!!) changes to both the bash source and the strace source....

Trouble is, can anyone save me some time and tell me what / where I should be changing?? Both have multiple files, and Ks of lines of code, and I will know what to do once I am in the right place, but the trouble is finding the right place to start!! So can someone tell me what files even to be looking at???


some more info on changes I want to make (to begin with)!!....

bash - hardcode in that every command should be preceded by a call to strace also

strace - hardcode in that every invocation should have its output saved to some file

I can change the genericity of this later - but for now I'd just like to get it working!!
Old 05-18-2004, 05:26 PM   #2
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,703

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
Some comments:
Builtin bash commands wouldn't be traced by such technique.
There is probably no need to patch the strace command itself, as if you can intercept all bash exec calls, you can also insert the options you want.
A simpler solution consist on launchin the shell itself under strace with the options "-o outFileName -ff", that will create a trace file for each subcommand you launch.
Old 05-18-2004, 05:27 PM   #3
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
here's a hint, for bash just grep for exec* and find where it is making calls to exec functions. and then do the exact same for strace, and right before strace calls exec open up your file and dup2 the descriptor to stdout.
Old 05-19-2004, 03:05 AM   #4
Registered: Nov 2003
Location: Ireland
Distribution: Red Hat 9
Posts: 49

Original Poster
Rep: Reputation: 15
cool, thanks for the suggestions.....


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Usage of strace mdb84 Linux - Software 1 03-25-2005 02:13 AM
Make and strace Clementine Linux - Newbie 0 02-16-2005 07:51 PM
strace question ronopolis Linux - Software 0 01-19-2005 10:41 AM
strace useradd phoenix_fei Programming 1 11-29-2004 10:32 AM
strace for ssh williewang Programming 1 08-03-2004 08:32 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration