I am trying to use script command for logging a bash session.
The script command is executed from withing a bash script but as soon as it i
You can use a trick within your shell script to start script or not start it. Based on a special argument, it can choose to execute itself with a special argument so that script is not started again.
This should most likely explain what I mean:
if [ "$1" != "noscript" ] ; then
# execute self with the noscript special arg so that the second execution DOES NOT start script again.
exec script -q -c "$0 noscript $1 $2 $3" /build/buildlog_`date '+%Y%m%d%H%M%S'`.log
echo Problem in $0, please check.
exit 1;
fi
...Rest of the script should follow here.
I have tried this, and it works well. Unless you are particular about the kind of arguments that need to be passed as well as the script is planned to be used by hostile users, this should suffice :).