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

  • 1
    What do you mean by 'the boot command' and 'while the script is still running'? Please tell us more details, and please give feedback to the answers and comments. Otherwise we can only guess, and the answer(s) might or might not be useful for your particular case. – sudodus Jan 8 at 16:55

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'

then logls

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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