3

I have an installation script for my software and I need it to run on both, Linux and AIX.

On Linux I can use a wrapper myinstaller.ksh like this one:

#!/usr/bin/ksh
script -c myrealinstaller.ksh /var/log/myinstaller.log

But on AIX script does not support the -c option.

How can I run my myrealinstaller.ksh inside the forked shell created by script?

1

You could enhance your wrapper script to detect the OS; if it's running on Linux, execute script -c ..., but if it's running on AIX, give the script-shell an overridden profile that only runs your installer, then exits:

$ cat myinstaller.ksh
#!/usr/bin/ksh

case $(uname -s) in
  (Linux)
        script -c myrealinstaller.ksh /var/log/myinstaller.log
        ;;
  (AIX)
        printf "ENV= ./myrealinstaller.ksh\nexit\n" > ./installer.profile
        trap 'rm -f ./installer.profile' INT
        ENV=./installer.profile script -q ./var/log/myinstaller.log
        rm ./installer.profile
        ;;
esac

I adjusted the paths to the script and logs to test it locally. The other factors involved are:

  • setting ENV to point to the overridden profile as we call script
  • calling script with -q to quiet it down a bit
  • importantly, unsetting ENV during the call to the real installer, so that we don't loop infinitely
  • telling the overridden profile to exit as soon as the installer is done

With a sample myrealinstaller.ksh of:

#!/bin/ksh
echo Hi, I am the real installer

The contents of ./var/log/myinstaller.log are:

Script command is started on Thu Mar 15 09:34:04 2018.
Hi, I am the real installer


Script command is complete on Thu Mar 15 09:34:04 2018.
2
  • Nice, this works very well. The only problem I found is the installer.profile which is not removed if the real installer is interrupted by ctrl+c.
    – Patrick
    Mar 15 '18 at 15:05
  • Glad to hear that it works, @P.Jksch! I've added a line to remove the installer.profile intermediate file if the user hits Control-C.
    – Jeff Schaller
    Mar 15 '18 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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