You are not logged in.

#1 2012-09-04 18:10:56

mosquitogang201
Member
Registered: 2012-06-19
Posts: 37

Cancel shutdown and suspend in bash script

I am writing a script that will automatically backup files on my computer to my network storage. This will run in the background as a cron job. Now assuming the script is running when I want to turn off my computer - is there any way I can have the suspend and shutdown process check if the backup script is running, and if so cancel, or at least provide me with the option to cancel the suspend/shutdown? I know that I can add scripts to /etc/pm/sleep.d and /etc/rc.shutdown.local that will run at the beginning of the process, but what actual command can I add that would stop the suspend/shutdown?

Offline

#2 2012-09-04 20:58:40

solamir
Member
From: Yaroslavl, Russia
Registered: 2012-09-02
Posts: 26
Website

Re: Cancel shutdown and suspend in bash script

Тry to use this piece of code:

#!/bin/bash
R=`pidof your_program_name`
if [[ $R -ne "" ]]
then
        while [[ $R -ne "" ]]
        do
            sleep 60
            R=`pidof your_program_name`
        done
else
    exit 0
fi

Accordingly, use custom hooks as described here. However I did not try this way.

Last edited by solamir (2012-09-04 21:05:27)

Offline

Board footer

Powered by FluxBB