If I run a bash script from the command line (with root permissions), is it possible to intercept the boot command within the script (while the script is still running) in order to log it? Thanks in advance
If editing the script is an option, you can add "logger" commands to log whatever you'd like to the system's logs.
on my Fedora system,
/usr/bin/logger $USER just ran $0
run from a bash prompt, added a log entry with the current timestamp, a source of my login ID[PID of logger command] just ran bash
you could add whatever information you wanted into that logger command's message. You can even pipe standard out of another command to the logger command.
$0 is a special variable that holds the name of the command currently running (bash when sitting at the bash prompt, but in a script, it would be the script's filename)
If you have access to the .bashrc or other startup files for the user who will be running processes you want to log, you could also create an alias.
I just tried:
alias logls='/usr/bin/logger listing a dir ; ls'
and got the listing of the current directory, and a timestamped log entry in the system logs.
if the alias was set to the same name as the original script it would be pretty transparent to the user(s). You would likely have to specify the full path to the original script in the definition of the alias of course.