Using Client Settings with Shell Scripts
Client settings on a shell script do not work as expected in AIX. This is because a shell script is not executed as a binary by a shell, rather, it is interpreted by the shell as a sequence of commands.
This limitation may be overcome by running the shell script in the context of a binary. A program is constructed to issue an execl(2)
of a shell with the desired script as its argument.
The client settings are then applied to the binary. When it executes, the client setting is applied to it by the agent code. Therefore, when it runs the shell, the client setting is inherited by the shell and is subsequently applied to all of the commands run as the script executes.
Following is an example program for implementing Client Settings:
cc testcode.c -o testcode
-------------------------
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
int
main(int argc, char *argv)
{
int rv;
rv = execl("/usr/bin/ksh", "ksh", "./testdata", NULL);
if (rv < 0) {
printf("execl errno %d\n", errno);
exit(1);
}
exit(0);
}
-
The file, testdata, contains the shell script text.
-
For test purposes, use a shell script that contains:
/usr/bin/cat
-
The client setting is applied to the testcode binary. When it runs, the client settings are applied to the components of the script, testdata.