How can you get script name in BSD process accounting file?

436 Views Asked by At

I'm trying to write a program to process the BSD-style process accounting file under Linux (/var/account/pacct).

When we start a script with either ./script_name or bash script_name, the process accounting record actually gets written out the the command bash. Presumably because that's the actual program doing the running.

What we'd like to see is the command script_name. Does anyone know of a way to get the script name written to the accounting file rather than the bash executable?

1

There are 1 best solutions below

3
On BEST ANSWER

Linux: Eternal Bash History with Snoopy.

Edit: As a hack alternative, you can periodically run ps -eo args

Edit by questioner (so I can accept the answer from the only SO'er who helped out :-):

I found that if you actually added "'#!bin/bash" to the file, it started showing up in pacct with the script name (tst) instead of the interpreter (bash).

My script was originally devoid of the hash-bang marker and it may be that bash had to re-exec itself or something like that. Anyway, it's fixed now.