如何获取 BSD 进程记帐文件中的脚本名称?
我正在尝试编写一个程序来处理Linux下的BSD风格的进程记帐文件(/var/account/pacct)。
当我们使用 ./script_name
或 bash script_name
启动脚本时,进程记帐记录实际上会通过命令 bash
写出。 大概是因为那是实际运行的程序。
我们希望看到的是命令script_name
。 有谁知道如何将脚本名称写入会计文件而不是 bash 可执行文件?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Linux:史努比永恒的 Bash 历史。
编辑:
作为一种黑客替代方案,您可以定期运行
ps -eo args
由提问者编辑(这样我就可以接受唯一提供帮助的 SO'er 的答案:-):
我发现,如果您实际上将“'
#!bin/bash
”添加到文件中,它就会开始显示在 pacct 中,并带有脚本名称 (tst
),而不是解释器(bash
)。我的脚本最初没有 hash-bang 标记,可能 bash 必须重新执行自身或类似的东西。 不管怎样,现在已经修好了。
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.