暂时防止linux关闭 [英] Temporarily prevent linux from shutting down

查看:51
本文介绍了暂时防止linux关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个备份脚本,该脚本每天在linux(Fedora 9)计算机上在后台运行.如果在备份过程中关闭计算机,则备份可能已损坏,因此我想编写一个小脚本,该脚本暂时禁用用户重新引导或关闭计算机的功能.

I have a backup script that runs in the background daily on my linux (Fedora 9) computer. If the computer is shut down while the backup is in progress the backup may be damaged so I would like to write a small script that temporarily disables the ability of the user to reboot or shut the computer down.

该脚本不一定是不可重复的,只是让系统用户知道备份正在进行中,因此不应该关闭它们.我已经在DBus Free桌面电源管理规范中看到了Inhibit方法: http://people.freedesktop.org/~hughsient/temp /power-management-spec-0.3.html 但这仅在系统未按用户要求显式处于空闲状态时才阻止关机.

It is not necessary that the script is uncirumventable, it's just to let the users of the system know that the backup is in progress and they shouldn't shut down. I've seen the Inhibit method on the DBus Free desktop power management spec: http://people.freedesktop.org/~hughsient/temp/power-management-spec-0.3.html but that only prevents shutdowns if the system is idle not explicitly at the users request.

在C/Python/Perl或bash中有简单的方法吗?

Is there an easy way to do this in C/Python/Perl or bash?

更新:为澄清上述问题,这是一台具有多个用户的计算机,但他们通过插入的键盘/鼠标顺序使用它.我不是在寻找能够阻止我以root身份入侵"该系统的系统.但是,当我从Gnome/GDM菜单

Update: To clarify the question above, it's a machine with multiple users, but who use it sequentially via the plugged in keyboard/mouse. I'm not looking for a system that would stop me "hacking" around it as root. But a script that would remind me (or another user) that the backup is still running when I choose shut down from the Gnome/GDM menus

推荐答案

另一种入门解决方案:在关闭过程中,系统运行/etc/init.d/中的脚本(或者实际上是/etc中的脚本) /rc.*/,但您会明白.)您可以在该目录中创建一个脚本来检查备份的状态,并延迟关闭直到备份完成.更好的是,它可以优雅地中断您的备份.

Another get-you-started solution: During shutdown, the system runs the scripts in /etc/init.d/ (or really, a script in /etc/rc.*/, but you get the idea.) You could create a script in that directory that checks the status of your backup, and delays shuts down until the backup completes. Or better yet, it gracefully interrupts your backup.

超级用户可以解决此脚本(例如,使用/sbin/halt),但是如果他们真的愿意这样做,则您不能阻止超级用户执行任何操作.

The super-user could workaround this script (with /sbin/halt for example,) but you can not prevent the super-user for doing anything if their mind is really set into doing it.

这篇关于暂时防止linux关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆