I'm working on a sysprep-style script which de-identifies a machine and gets it ready for templatizing. The last task that I'd like to perform (before shutdown) is clearing the bash history for the root user. I can execute
HISTFILE=~/.bash_history
set -o history
>$HISTFILE
history -c
from within the script. The issue is the history stored in memory for the interactive root session that executes the script is written to $HISTFILE at the end of that session. I want the sysprep script to be the last thing executed (the last line in the script is shutdown now -h).
If necessary, I can clear the history manually from the interactive session before shutdown, but I'd like to make it part of my script. Any suggestions?
Not sure if it matters but this is for RHEL8.
chmod u-wthe HISTFILE, but that would leave the HISTFILE unwritable going forward.