Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have some scripts and some commands in the scripts are like this

./executable arg1 arg2 .. argn

I want to change the above command to

LD_PRELOAD=/some/lib ./executable my_arg1 my_argn arg1 arg2 argn; some_other_command

One way to change the scripts, but I don't want to do that, instead I want to intercept those commands, change those commands and run them. How can I do that?

share|improve this question
    
Do you have permission to move the existing ./executable to a new location? If so, the answer is relatively easy. –  John1024 Jan 31 at 19:30
    
Yes, I have the root access in system. –  user Jan 31 at 19:31

1 Answer 1

First, move the existing executable to a new location:

mv ./executable ./executable.original

Second, create a shell script in it place. Place the following commands in a new file called ./executable:

#!/bin/sh
LD_PRELOAD=/some/lib ./executable.original my_arg1 my_argn "$@"
some_other_command

The shell will replace the incantation "$@" with arg1 arg2 argn as supplied by the calling program.

Third, set the execute bit on your new file:

chmod a+rx ./executable
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.