Temporarily prevent linux from shutting down

前端 未结 6 2079
暖寄归人
暖寄归人 2021-01-11 14:06

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 dama

6条回答
  •  没有蜡笔的小新
    2021-01-11 14:16

    More a get-you-started than a complete solution, you could alias the shutdown command away, and then use a script like

    #!/bin/sh
    ps -ef|grep backupprocess|grep -v grep > /dev/null
    if [ "$?" -eq 0 ]; then
     echo Backup in progress: aborted shutdown
     exit 0
    else
     echo Backup not in progress: shutting down
     shutdown-alias -h now
    fi
    

    saved in the user's path as shutdown. I expect there would be some variation dependant on how your users invoke shutdown (Window manager icons/command line) and perhaps for different distros too.

提交回复
热议问题