views:

164

answers:

1

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?

+2  A: 

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.

eed3si9n
Interesting find. We can't integrate GPL code into ours (or ship it) unfortunately, but I'll give you an upvote since I suspect this may come in handy for a personal project of mine.
paxdiablo
After edit: I thought of that but we're already collecting pacct info for other stuff and we don't want to load up the boxes with any more work. Periodic ps'ing may miss things as well and our customer might not look too favourably on that :-)
paxdiablo
Thanks for help, 33d3si9g. I fixed it and added the fix to your answer so I could accept it - I don't like leaving unaccepted questions on my stats page :-).
paxdiablo