在 Ubuntu 中关闭前执行脚本

jua*_*ren 5 linux shutdown gnome ubuntu ubuntu-10.04

当我关闭计算机时,我想显示一些我在离开办公室之前必须完成的待处理任务。

我有一个本地应用程序来管理这些任务,所以基本上我只想运行一个命令,并在我杀死执行的应用程序后关闭。

我已经尝试过这些选项:

/etc/gdm/PostSession/Default
Run Code Online (Sandbox Code Playgroud)

这仅在我选择 LogOut 选项而不是 Shutdown 时有效。

/etc/rc0.d/K01mycustomscript
Run Code Online (Sandbox Code Playgroud)

在 X 被杀死后执行脚本。

$HOME/.bash_logout
Run Code Online (Sandbox Code Playgroud)

这看起来什么都不做。

./app-to-run && sudo shutdown -h now
Run Code Online (Sandbox Code Playgroud)

我不喜欢这个有两个原因:它提示输入 sudo 密码,而且我不能使用我的笔记本电脑关机按钮。

我正在使用 Ubuntu 10.04。

Che*_*evy 1

看看/etc/rc0.d/README- 它说

The scripts in this directory are executed once when entering
runlevel 0.

The scripts are all symbolic links whose targets are located in
/etc/init.d/ .

Generally it is not necessary to alter the scripts in this directory.
Their purpose is to stop all services and to make the system ready
for shutdown.
Run Code Online (Sandbox Code Playgroud)

您将需要创建一个脚本/etc/init.d,然后将它们符号链接到/etc/rc0.d/以使脚本在关闭时运行。