Long story short: I would like to track the way in which some executables are called to track some system behaviour. Let's say that I have an executable:
/usr/bin/do_stuff
And it is actually called by a number of different names via symlink:
/usr/bin/make_tea -> /usr/bin/do_stuff
/usr/bin/make_coffee -> /usr/bin/do_stuff
and so on. Clearly, do_stuff
is going to use the first argument it receives to determine what action is actually takes, and the rest of the arguments will be handled in the light of that.
I would like to record ever call to /usr/bin/do_stuff
(and the full list of arguments). If there were no symlinks, I would simply move do_stuff
to do_stuff_real
and write a script
#!/bin/sh
echo "$0 $@" >> logfile
/usr/bin/do_stuff_real "$@"
However, as I know that it will examine the name that it is called by, this won't work. How does one write a script to achieve the same but still pass on to do_stuff
the right 'executable used name'?
For the record, to avoid answers on these lines:
- I know that I can do it in C (using execve), but it would be a lot easier if I could, in this case, just use a shell script.
- I can't simply replace
do_stuff
with a logging programme.